編輯:這已被確定爲問題#1055 - Expression of SELECT list is not in GROUP BY clause and contains nonaggregated column this is incompatible with sql_mode=only_full_group_byMySQL處理GROUP BY。獲得ONLY_FULL_GROUP_BY錯誤
這是不正確的可能重複,由於答案是改變全球的sql_mode設置。 MySQL的改變基於functional dependencies and returning arbitrary data
我的問題有很好的理由ONLY_FULL_GROUP_BY默認並回答給一個簡短而準確的解釋上的錯誤,以及如何使用更詳細的語句來規避它。閱讀
感謝,表如下:
+-----------+-------------+-----------+----------+-------+
| productID | productCode | name | quantity | price |
+-----------+-------------+-----------+----------+-------+
| 1001 | PEN | Pen Red | 5000 | 1.23 |
| 1002 | PEN | Pen Blue | 8000 | 1.25 |
| 1003 | PEN | Pen Black | 2000 | 1.25 |
| 1004 | PEC | Pencil 2B | 10000 | 0.48 |
| 1005 | PEC | Pencil 2H | 8000 | 0.49 |
+-----------+-------------+-----------+----------+-------+
所以,如果我運行命令:
SELECT * FROM products GROUP BY productCode;
我收到以下錯誤:
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'southwind.products.productID' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
所以從我收集的內容是mysql documentation,因爲我的GROUP BY參數中有重複的值拋出錯誤,拒絕任意返回。我寧願不禁用這個,所以任何幫助瞭解我失蹤,使查詢工作非常感謝。
謝謝。
根據您的模式
因此,您希望爲每個組返回哪個行,因爲每個productCode中沒有相同的行? – Mihai