求分类统计sql语句
一个表包含物料编号,数量,库存,
如 物料编号 数量 库存
8B00X1 30 BJ
8B00X1 5 SH
8B00X1 7 GZ
8B00X1 9 SZ
8B0004 30 SH
..........
现在要统计每个子库存的物料编号的数量
表现形式为:
物料编号 BJ SH GZ SZ
8B00X1 30 5 7 9
8B0004 30
这个sql语句怎么写,谢谢!
------解决方案--------------------SELECT
SUM(CASE B.SUBINVENTORY_CODE when 'SZ01 ' THEN B.TOTAL_QOH ELSE 0 END )AS SZ01,
SUM(CASE B.SUBINVENTORY_CODE when 'SZ02 ' THEN B.TOTAL_QOH ELSE 0 END )AS SZ02,
NVL(A.CROSS_REFERENCE,C.SEGMENT1) AS OLD_NUM,
C.SEGMENT1 AS NEW_NUM,
C.DESCRIPTION,
B.TOTAL_QOH,
B.SUBINVENTORY_CODE
FROM
INV.MTL_CROSS_REFERENCES A,APPS.MTL_ONHAND_SUB_V B,INV.MTL_SYSTEM_ITEMS_B C
WHERE
B.INVENTORY_ITEM_ID = A.INVENTORY_ITEM_ID(+)
AND
B.INVENTORY_ITEM_ID = C.INVENTORY_ITEM_ID
AND
C.ORGANIZATION_ID =45
GROUP BY
NVL(A.CROSS_REFERENCE,C.SEGMENT1),
C.SEGMENT1,
C.DESCRIPTION,
B.TOTAL_QOH,
B.SUBINVENTORY_CODE