我遇到了SQL查詢。我正在做的SELECT子句中的子查詢和DB2提示一個錯誤-119講:DB2:Select子句中的子集干涉子查詢
"An expression starting with "FACILITY_ID" specified in a SELECT clause, HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or it is in a SELECT clause, HAVING clause, or ORDER BY clause with a column function and no GROUP BY clause is specified. SQL Code: -119, SQL State: 42803"
我不知道如何將在GROUP BY NUMTAGS。我試圖在GROUP BY子句中包含BC.ITEM,但沒有結果。我不知道如何在網上找到這個,我看到的論壇沒有用。
如果有人能解釋我如何修補或粘貼一個鏈接,我可以尋找解決方案,我將不勝感激。
的SQL查詢DB2和它的到這裏:
SELECT SS.NAME, B.DESTINATION_ID, P.DESCRIPTION, B.LAST_READ_DATE, B.LABEL,
(SELECT COUNT(BC.ITEM)
FROM PROJECT_DB.BOX_CONTENT BC
WHERE BC.FACILITY_ID = B.FACILITY_ID
AND BC.BOX_ID = B.BOX_ID
GROUP BY BC.ITEM) AS NUMTAGS,
B.BOX_ID
FROM PROJECT_DB.BOX B
INNER JOIN MAINDB.DESTINATION P ON B.DESTINATION_ID = P.DESTINATION_ID
INNER JOIN MAINDB.WAREHOUSE_DESTINATION_SECTION WH
ON B.DESTINATION_ID = WH.DESTINATION_ID
AND B.WAREHOUSE_ID = WH.WAREHOUSE_ID
INNER JOIN MAINDB.SECTION S ON S.SECTION = WH.SECTION
AND S.SECTION_TYPE = B.SECTION_TYPE
INNER JOIN MAINDB.DESTINATION_SET SS
ON SS.DESTINATION_SET_ID = S.DESTINATION_SET_ID
WHERE B.WAREHOUSE_ID = 100
GROUP BY B.BOX_ID, B.FACILITY_ID, B.DESTINATION_ID, B.LAST_READ_DATE, B.LABEL, P.DESCRIPTION, SS.NAME
我所需要的「集團通過」由於WAREHOUSE_DESTINATION_SECTION表的性質。這個表是另一個之間的連接,我沒有限制和過濾結果所需的可變參數,所以我需要「Group by」。 現在事情已經解決了。 – madtyn