标签:strong 产品 http 仓库 group by info from 技术 mic
背景是在公司要开发新产品,所有重新设计了此处的展示样式。最先没在意,后来仔细一看,需要同时按照商品和仓库维度来统计。大致效果图如下:
不说废话,直接贴SQL!
SELECT
g.gid,g.goodsname,g.code. . .
SUM(CASE WHEN a.sid = @sid0 THEN a.qty ELSE 0 END) AS qty,#账面库存
SUM(CASE WHEN a.sid = @sid0 THEN a.realqty ELSE 0 END) AS realqty,#实物库存
SUM(CASE WHEN a.sid = @sid1 THEN a.qty ELSE 0 END) AS qty,#账面库存
SUM(CASE WHEN a.sid = @sid1 THEN a.realqty ELSE 0 END) AS realqty,#实物库存
SUM(CASE WHEN a.sid = @sid2 THEN a.qty ELSE 0 END) AS qty,#账面库存
SUM(CASE WHEN a.sid = @sid2 THEN a.realqty ELSE 0 END) AS realqty,#实物库存
.
.
.
.
FROM goods g
LEFT JOIN stock a ON g.gid = a.gid
WHERE #Condition
GROUP BY g.gid
这里的@sid0,@sid1,@sid2就是需要展示的仓库维度,
再通过商品GID来分组,就可以实现上图的库存二维统计了。
—— huiyuangg520
标签:strong 产品 http 仓库 group by info from 技术 mic
原文地址:https://www.cnblogs.com/huiyuangg520/p/12128263.html