![](https://i-blog.csdnimg.cn/blog_migrate/88d64d61dd684568b60dab066a6c5c7a.jpeg)
![](https://i-blog.csdnimg.cn/blog_migrate/cd79514e86b5616c6ae62d1dd0eb03b1.jpeg)
思路:
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
结果图:
![](https://i-blog.csdnimg.cn/blog_migrate/b692d2b7dffe02db922f57da07c797da.png)