我使用的是SQL Server 2005中我得到這個錯誤:「多部分組成的標識符不能被束縛」的錯誤
*The multi-part identifier "ms.MOP_desc" could not be bound.*
我測試了上述2個選擇查詢和他們工作得很好分別,但我當我結合這些查詢時出現錯誤。我可以告訴我這個查詢出了什麼問題嗎?謝謝。
SELECT SUM(Amount) AS TotalAmount, ms.MOP_desc
FROM
(
SELECT SUM(hd.delivery_value) AS Amount, ms.MOP_desc
FROM TRANSACTION_HEADER AS th
INNER JOIN TRANSACTION_DETAIL AS td
ON th.transaction_number = td.transaction_number
LEFT JOIN hose_delivery hd
ON td.delivery_id = hd.delivery_id
LEFT JOIN product pr
ON pr.product_id = td.product_id
INNER JOIN MOP_Setting AS ms
ON hd.MOP_ID = ms.MOP_ID
WHERE hd.delivery_value > 0
AND (th.USER_PERIOD_ID IN (13))
AND (hd.MOP_ID IN (1))
AND hd.Cleared_By != '0'
GROUP BY ms.MOP_desc
UNION ALL
SELECT SUM(td.quantity * td.price_sold) AS Amount, ms.MOP_desc
FROM TRANSACTION_HEADER AS th
INNER JOIN TRANSACTION_DETAIL AS td
ON th.transaction_number = td.transaction_number
INNER JOIN MOP_Setting AS ms
ON th.MOP_ID = ms.MOP_ID
WHERE (th.USER_PERIOD_ID IN (13))
AND (th.MOP_ID IN (1))
GROUP BY ms.MOP_desc
)t
謝謝你的解釋。它確實有幫助。 – ixora