我得到了這個說法GROUP BY SQL語句錯誤
SELECT ITEM.ITEMID, ITEMNAME, QUANTITY AS "QUANTITY SOLD"
FROM ORDERITEM,
NBUSER."ORDER",
PAYMENT,
ITEM
WHERE NBUSER."ORDER".PAYMENTID = PAYMENT.PAYMENTID
AND ITEM.ITEMID = ORDERITEM.ITEMID
AND PAYMENT.PAYMENTDATE BETWEEN '4/1/2017' AND '4/30/2017'
GROUP BY ITEM.ITEMID
ORDER BY ITEM.ITEMID DESC;
但它不斷給我這個錯誤:
[Exception, Error code 30,000, SQLState 42Y36] Column reference 'ITEM.ITEMNAME' is invalid, or is part of an invalid expression. For a SELECT list with a GROUP BY, the columns and expressions being selected may only contain valid grouping expressions and valid aggregate expressions. Line 1, column 1
我想加入類似的itemid記錄在一起,並添加量彌補所有相同的itemid。
一般的GROUP BY規則說:如果指定了GROUP BY子句,SELECT列表中的每個列引用必須標識一個分組列或者是一個set函數的參數。 – jarlh
錯誤是自我解釋讀取它。您應該將選擇列表列添加到group by子句中或使用聚合函數。 – Sankar
今天提示:切換到現代,明確的JOIN語法。易於編寫(沒有錯誤),更易於閱讀(和維護),並且在需要時更容易轉換爲外部聯接。 – jarlh