declare @tb table(a nvarchar(100)) insert into @tb select '44' union all select '33' union all select '44' union all select 'bb' union all select 'ee' union all select 'ee' union all select 'ee' select * from @tbselect a,count(a) 数量 from @tb group by a order by count(a)desc
create table test(a char(20)) insert into testselect '44' union all select '33' union all select '44' union all select 'bb' union all select 'ee' union all select 'ee' union all select 'ee' select a,count(a)b from test group by a order by b desc
declare @tb table(a varchar(10)) insert @tb select '44' union all select '33' union all select '44' union all select 'bb' union all select 'ee' union all select 'ee' union all select 'ee' select a,count(a) num from @tb group by a order by num desc /* a num ----------------- ee 3 44 2 bb 1 33 1 */
insert into @tb select '44'
union all select '33'
union all select '44'
union all select 'bb'
union all select 'ee'
union all select 'ee'
union all select 'ee'
select * from @tbselect a,count(a) 数量 from @tb group by a order by count(a)desc
insert into testselect '44' union all
select '33' union all
select '44' union all
select 'bb' union all
select 'ee' union all
select 'ee' union all
select 'ee' select a,count(a)b
from test
group by a
order by b desc
insert @tb
select '44' union all
select '33' union all
select '44' union all
select 'bb' union all
select 'ee' union all
select 'ee' union all
select 'ee'
select a,count(a) num
from @tb
group by a
order by num desc
/*
a num
-----------------
ee 3
44 2
bb 1
33 1
*/