Select 酒菜编号,点单类型,case 点单类型 when '点单' then sum(数量) end as 点单数量,case 点单类型 when '退单' then sum(数量) end as 退单数量,sum(数量) as 总数 from 表名 group by 酒菜编号,点单类型
运行测试
SELECT inno, inout, CASE inout WHEN '入库' THEN SUM(QTY) END AS 入库数量, CASE inout WHEN '出库' THEN SUM(QTY) END AS 出库数量
FROM TabInOut
GROUP BY inno, inout
ORDER BY inno DESC, inout DESC
发表评论