思路:
SQL:
1 select tt.month as '月份',sum(tt.rp) as '实体商品',sum(tt.vp) as '虚拟商品' from ( 2 select month, 3 sum(IF(goods_type =1,amount,0.00)) as 'rp', 4 sum(IF(goods_type =2,amount,0.00)) as 'vp' 5 from ( 6 select id, 7 substring(date_format(From_unixtime(sold_time),'%Y-%m-%d'),1,7) as month, 8 sum(amount) as amount, 9 goods_type 10 from goods_count 11 group by substring(date_format(From_unixtime(sold_time),'%Y-%m-%d'),1,7),goods_type 12 ) t 13 group by month,goods_type ORDER BY month 14 ) tt group BY tt.month
结果图: