sql取值分类
求以下语句更改:
select InvCode as 存货编码,OpSeq as 工序行号,OpCode as 工序代号,opDescription as 工序说明,ScrapQty as 报废数量,ScrapReasonCode as 报废原因码,ScrapReasonName as 报废说明
from v_fc_moroutingbilllist
结果:
需要的结果:
SQL 编码
[解决办法]
SELECT InvCode AS 存货编码 ,
OpSeq AS 工序行号 ,
OpCode AS 工序代号 ,
opDescription AS 工序说明 ,
[杂质] = MAX(CASE WHEN ScrapReasonName = '杂质' THEN ScrapQty
ELSE 0
END) ,
[冲坏] = MAX(CASE WHEN ScrapReasonName = '冲坏' THEN ScrapQty
ELSE 0
END) ,
[模具脏] = MAX(CASE WHEN ScrapReasonName = '模具脏' THEN ScrapQty
ELSE 0
END)
FROM v_fc_moroutingbilllist
GROUP BY InvCode ,
OpSeq ,
OpCode ,
opDescription