declare @t table(a varchar(10),b int) insert @t select 'DDD', 100 union all select 'BBB' , 5 union all select 'CCC' , 4 union all select 'AAA' , 20 union all select 'DDD' , 30 union all select 'AAA' , 40 select a.* from @t a inner join (select a,sum(b) sb from @t group by a) b on a.a=b.a order by sb desc,b desc /* a b DDD 100 DDD 30 AAA 40 AAA 20 BBB 5 CCC 4*/
这样?
select 厂商,数量 from 表名 order by 数量 desc
insert @t select 'DDD', 100
union all select 'BBB' , 5
union all select 'CCC' , 4
union all select 'AAA' , 20
union all select 'DDD' , 30
union all select 'AAA' , 40 select a.* from @t a
inner join (select a,sum(b) sb from @t group by a) b
on a.a=b.a
order by sb desc,b desc
/*
a b
DDD 100
DDD 30
AAA 40
AAA 20
BBB 5
CCC 4*/