sql - Create VIEW (count duplicate values in column) -
i have little project sql database has table column.
question: how create view in sql server, count how many duplicate values have in column , show number in next column.
here below can see result want take.
|id|name|count| |1 |tom | | |2 |tom | | |3 |tom | | | | | 3 | |4 |leo | | | | | 1 |
a view select statement words create view as
before select
. allows example, 1 person (dba) maintain (create/alter) complex views, while person (developer) has rights select them.
so use @stidgeon's answer (below):
create view mycounts select name, count(id) counts table group name
and later can query
select * mycounts counts > 1 order name
or whatever need do. note order by
not allowed in views in sql server.
Comments
Post a Comment