select 姓名列,count(1) as [重复次数] from 表名 group by 姓名列 having count(1)>=2 order by 重复次数 desc
追问应该是这种效果:
小明
小明
小明
小红
小红
小小
就是说重复次数最大的放到最前面,显示所有重复数据?请问???
追答select * from 表名 as t1
left join (select top(10000) 姓名列名,count(1) as 重复次数 from 表名 group by 姓名列名 having count(1)>=2 order by 重复次数 desc) as t2
on t1.姓名列名=t2.姓名列名
where t1.姓名列名 is not null and 重复次数 is not null
order by 重复次数 desc