查询表中某字段有重复记录的个数

--查出表中有重复的id的记录,并计算相同id的数量
select id,count(id) from @table group by id having(count(id)>1)

其中,group by id,是按id字段分组查询:

select id,count(id) from @table group by id

可以得到各不同id的数量合计

having(count(id)>1)判断数量大于1,也就是有重复id的记录

原文地址:https://www.cnblogs.com/xuxiaona/p/2987245.html