mysql分组,行转列
 
 
mysql分组,行转列

 

思路:

mysql分组,行转列

 
 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

 

 
 结果图:
 
 mysql分组,行转列
 
 
 
 
 
 
 
 
 
 
 
 
 
 

相关文章:

  • 2021-06-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
猜你喜欢
  • 2021-05-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2021-08-07
  • 2021-04-15
相关资源
相似解决方案