sqlserver 做一个数据表,5百万条记录,其中一个字段有很多重复,我想查找这个字段其中重复次数最多的记录。将该记录和重复次数显示出来。求sql语句的写法?

解决方案 »

  1.   

    select top 1 重复字段 from tb group by 重复字段 order by  count(*) desc 
      

  2.   

    select top 1 重复字段, count(*) as 重复次数
    from tb group by 重复字段 order by  count(*) desc 
      

  3.   


    select a.*,b.重复次数 from tbName a,(
    select top 1 重复字段 as 重复, count(*) as 重复次数
    from tbName group by 重复字段 order by  count(*) desc )b
    where a.重复字段=b.重复