mysql根据条件计算mcgross

时间:2011-03-23 05:05:26

标签: mysql

Select p.item_name,
  sum(p.mc_gross Case when u.ag_code!=0),
  Sum(p.mc_gross Case when u.ag_code=0)                                
From table1 as p,table2 as u
Where p.payment_status = 'success'
Group By p.item_name 

此查询有错误

mcgross,ag_code,cdate,mdate,item_name是我表格中的列名

我的结果想要这样

item_name   sum1    Sum2
Bronze  11.71   9.99
Silver  35.82   540.88
Enterprise  145.3   308.94
Silver  156.94  1
Bronze  451.86  7.99
Gold    565.56  1019.74
Enterprise  671.17  608.88
Gold    71.23   38.99

1 个答案:

答案 0 :(得分:0)

很难说没有更多信息,但请尝试将其更改为group by Item_name