declare @t table(xx int) insert into @t select 1 insert into @t select 2 insert into @t select 3 insert into @t select 4 insert into @t select 4 insert into @t select 2 insert into @t select 3 insert into @t select 3 insert into @t select 4 insert into @t select 2 insert into @t select 1 insert into @t select 1select xx,num=count(*) from @t group by xx order by xx/* xx num ----------- ----------- 1 3 2 3 3 3 4 3 */
insert into @t select 1
insert into @t select 2
insert into @t select 3
insert into @t select 4
insert into @t select 4
insert into @t select 2
insert into @t select 3
insert into @t select 3
insert into @t select 4
insert into @t select 2
insert into @t select 1
insert into @t select 1select xx,num=count(*) from @t group by xx order by xx/*
xx num
----------- -----------
1 3
2 3
3 3
4 3
*/