本帖最后由 newtypebao 于 2011-07-06 11:28:48 编辑

解决方案 »

  1.   

    select  Name,sum(if(Type='type1',Price,0)),
    sum(if(Type='type2',Price,0)),sum(if(Type='type3',Price,0))
     from tt group by Name
      

  2.   

    我编辑的时候格式还是好好的 怎么提交后格式就变这样了
    我再补充下吧。。
    数据就是每种Name的都有几种Type 并且每条数据都有个price
    汇总的数据是
    每种Name 每种Type  的price求和
      

  3.   

    select name,sum(case when type='type1' then price else 0 end) as SumType1Price,
    sum(case when type='type2' then price else 0 end) as SumType2Price 
    from tb
    grop by name
      

  4.   


    请问下如果我还要求每种type的count可以么
    count(if(Type='type2',*,0))
    这样貌似不行。。
    count(if(Type='type2',1,0))
    这样貌似也不行。。
      

  5.   

    count的话也是用sum
    sum(if(Type='type2',1,0)),也就是符合条件的行算1,不符合条件的行算0