select top 1 col,count(1) from tb a
group by col order by count(1) desc

解决方案 »

  1.   

    select col,cnt=count(1) into # from tb a
    group by col 
    select * from # a
    where not exists(select 1 from # where cnt>a.cnt)
    drop table #
      

  2.   

    select top 1  x from tb group by x desc having count(x)>0
      

  3.   

    create table tb(col1 int,col2 int)
    insert into tb
    select 2,3 union all
    select 2,13 union all
    select 2,23 union all
    select 1,3 union all
    select 1,13 union all
    select 1,23 union all
    select 1,33 union all
    select 1,35 union all
    select 3,3 union all
    select 3,13 union all
    select 3,23 union all
    select 3,33 
    go
    select   top 1 col1,count(1) from tb group by col1 order by count(*) descdrop table tb
      

  4.   

    create table tb(col1 int,col2 int)
    insert into tb
    select 2,3 union all
    select 2,13 union all
    select 2,23 union all
    select 1,3 union all
    select 1,13 union all
    select 1,23 union all
    select 1,33 union all
    select 1,35 union all
    select 3,3 union all
    select 3,13 union all
    select 3,23 union all
    select 3,33 
    go
    select col1,cnt=count(1) into # from tb a
    group by col1 
    select * from # a
    where not exists(select 1 from # where cnt>a.cnt)
    drop table #,tb