统计每个商品每个月的销量???

SELECT 
M.B2B_SKU AS SKU,G.MATERIALNAME AS GOODNAME,
SUM(CASE MONTH(O.SUBMITTIME) WHEN '1' THEN G.PURCHASQUANTITY ELSE 0 END) AS one,  
SUM(CASE MONTH(O.SUBMITTIME) WHEN '2' THEN G.PURCHASQUANTITY ELSE 0 END) AS two,  
SUM(CASE MONTH(O.SUBMITTIME) WHEN '3' THEN G.PURCHASQUANTITY ELSE 0 END) AS three,  
SUM(CASE MONTH(O.SUBMITTIME) WHEN '4' THEN G.PURCHASQUANTITY ELSE 0 END) AS four,  
SUM(CASE MONTH(O.SUBMITTIME) WHEN '5' THEN G.PURCHASQUANTITY ELSE 0 END) AS five,  
SUM(CASE MONTH(O.SUBMITTIME) WHEN '6' THEN G.PURCHASQUANTITY ELSE 0 END) AS six,  
SUM(CASE MONTH(O.SUBMITTIME) WHEN '7' THEN G.PURCHASQUANTITY ELSE 0 END) AS seven,  
SUM(CASE MONTH(O.SUBMITTIME) WHEN '8' THEN G.PURCHASQUANTITY ELSE 0 END) AS eight,  
SUM(CASE MONTH(O.SUBMITTIME) WHEN '9' THEN G.PURCHASQUANTITY ELSE 0 END) AS nine,  
SUM(CASE MONTH(O.SUBMITTIME) WHEN '10' THEN G.PURCHASQUANTITY ELSE 0 END) AS ten,  
SUM(CASE MONTH(O.SUBMITTIME) WHEN '11' THEN G.PURCHASQUANTITY ELSE 0 END) AS eleven,  
SUM(CASE MONTH(O.SUBMITTIME) WHEN '12' THEN G.PURCHASQUANTITY ELSE 0 END) AS twelve,

SUM(G.PURCHASQUANTITY) AS TOTAL  
FROM SHOP.B2B_ORDERS O
INNER JOIN SHOP.B2B_ORDER_GOODS G  ON G.ORDERNO = O.ORDERNO
INNER JOIN SHOP.B2B_SELLER_GOODS S ON S.SGID = G.SGID
INNER JOIN SHOP.MATERIAL_MODELS M ON  M.ID = S.MATERIALM
  • 0
    点赞
  • 0
    评论
  • 2
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值