MySQL 中“SELECT 列表不在GROUP BY 子句中”錯誤的疑難解答
錯誤“SELECT 列表的表達式#1 不在GROUP BY 子句中」當查詢結果包含非聚合列時,MySQL 中通常會出現「GROUP BY 子句並包含非聚合列」的情況。包含在 GROUP BY 子句中。這是由於 sql_mode=only_full_group_by 設置,該設置強制執行更嚴格的分組規則。
要解決此問題,有多種解決方案:
SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
SELECT * FROM `tbl_customer_pod_uploads` WHERE `load_id` = '78' AND `status` = 'Active' GROUP BY `proof_type`, `id`
SELECT `proof_type`, COUNT(*) AS `document_count` FROM `tbl_customer_pod_uploads` WHERE `load_id` = '78' AND `status` = 'Active' GROUP BY `proof_type`
以上是如何解決MySQL的「SELECT清單不在GROUP BY子句中」錯誤?的詳細內容。更多資訊請關注PHP中文網其他相關文章!