表结构:
         品  牌    款式  实际售价
水果派 3452    50
         蔬菜派   3453    30
         水果派 3452    50
         水果派 3452    50
         蔬菜派   3453    30
现在想要做一个统计销售的排行表,实现这样的排列
 
 排位    品牌   款式   销量
 1       水果派  3452    3
 2       蔬菜派  3453    2
我知道可能要用group by,但想不出如何给它加一些条件??
          

解决方案 »

  1.   

    自己解决了,
    select 货物名称,款式,count(*) 个数 from 售货表 group by 货物名称,款式 order by 个数 desc
    select * from 售货表
      

  2.   


    create table test ( 品牌 varchar(20) , 款式 int,  实际售价 int)insert test
    select '水果派', 3452  ,  50  union allselect '蔬菜派', 3453  ,  30  union allselect '水果派', 3452  ,  50  union allselect '蔬菜派', 3453  ,  30 select 品牌,款式 ,count(*) 数量
    from test
    group by 品牌,款式