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 #
select top 1 x from tb group by x desc having count(x)>0
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
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
group by col
select * from # a
where not exists(select 1 from # where cnt>a.cnt)
drop table #
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
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