MySQL this is incompatible with sql_mode=only_full_group_by-錯誤解決

流浪2024發表於2024-08-08

mysql執行group by時遇到下面提示:

SELECT list is not in GROUP BY clause and contains nonaggregated column 'crm.b.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

原因:在sql執行時,出現該原因:就是輸出的結果是叫target list,就是select後面跟著的欄位;還有一個地方group by column,就是 group by後面跟著的欄位。由於開啟ONLY_FULL_GROUP_BY的設定,所以如果一個欄位沒有在target list 和group by欄位中同時出現,或者是聚合函式的值的話,那麼這條sql查詢是被mysql認為非法的,會報錯誤

執行以下sql:

mysql> set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
mysql> set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

原文連結:https://blog.csdn.net/zhoupenghui168/article/details/91801102

相關文章