我想统计一个表中有多少重复的记录..
我这样写的..
select count(1) from(
select count(0) from mappingdept group by src_deptid having count (src_deptID)>1 order by 1 desc)
有没有更简单的方法呢?谢谢!
你的重复记录是按照src_deptid判断的吧~
提供两种思路:
总记录-唯一记录数(SELECT COUNT(*)-(SELECT COUNT(DISTINCT src_deptID) FROM mappingdept) FROM mappingdept)
分组排名,计算大于1的数据(
select COUNT(*) from (SELECT row=ROW_NUMBER() OVER(PARTITION BY src_deptID ORDER BY src_deptID) FROM mappingdept)t
WHERE t.row>1
)