select t.* from 表 t order by (select max(数量) from 表 where 厂商=t.厂商) desc,数量 desc

解决方案 »

  1.   


    这样?
    select 厂商,数量 from 表名 order by 数量 desc
      

  2.   

    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*/