我正在尝试输出以下数据,每个位置只有一行。现在它显示:120.... 120... 120...
我试图让它将所有值加起来为 120 行,123 行,128 行等。我认为这与 DISTINCT 子句有关,但我看到这个有点脑筋急转弯......
SELECT ICLOCATION.LOCATION,
ICLOCATION.NAME,
ITEMMAST.ITEM,
ITEMMAST.DESCRIPTION,
ITEMLOC.SOH_QTY,
OnOrder,
AllocQty,
SUM(ITEMLOC.SOH_QTY + t.OnOrder - t.AllocQty) AS NetOnHand
FROM (SELECT ITEMLOC.ITEM,
SUM(ISNULL(ITEMLOC.ONORDER_QTY, 0) + ITEMLOC.INTRANS_QTY + ITEMLOC.WIP_QTY) AS OnOrder,
SUM(ITEMLOC.ALLOC_QTY + ITEMLOC.UNALLOC_QTY + ITEMLOC.BACKORD_QTY + ITEMLOC.IN_PROC_QTY + ITEMLOC.HOLD_QTY) AS AllocQty
FROM ITEMLOC
GROUP BY ITEMLOC.ITEM) t
INNER JOIN ITEMLOC
ON ITEMLOC.ITEM = t.ITEM
INNER JOIN ITEMMAST
ON ITEMLOC.ITEM = ITEMMAST.ITEM
INNER JOIN ICLOCATION
ON ITEMLOC.COMPANY = ICLOCATION.COMPANY
WHERE ( ICLOCATION.LOCATION = '120'
OR ICLOCATION.LOCATION = '123'
OR ICLOCATION.LOCATION = '128'
OR ICLOCATION.LOCATION = '129'
OR ICLOCATION.LOCATION = 'HD41D'
OR ICLOCATION.LOCATION = 'HD21H'
OR ICLOCATION.LOCATION = 'HD91H' )
AND ITEMMAST.ITEM = '0210950'
GROUP BY ITEMMAST.ITEM,
ICLOCATION.LOCATION,
ICLOCATION.NAME,
ITEMMAST.DESCRIPTION,
ITEMLOC.SOH_QTY,
ITEMLOC.ITEM,
OnOrder,
AllocQty
ORDER BY ICLOCATION.LOCATION,
ITEMMAST.ITEM