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

admin 2014年5月2日00:04:24MSSQLSERVER评论1,202 次浏览阅读模式



--查出表中有重复的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的记录


相关文章
weinxin
我的微信
微信扫一扫
admin
  • 本文由 发表于 2014年5月2日00:04:24
  • 转载请务必保留本文链接:https://anyun.org/a/jishuguanzhu/database/mssqlserver/2014/0502/238.html

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: