MySQL GROUP BY 出現 sql_mode=only_full_group_by 問題處理

報錯大概如下:

"Error 1055: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'xxx' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by"

解決方式就是將 sql_mode中的only_full_group_by去掉。

我的處理方式是直接在執行group by操作之前執行如下SQL語句,使得對當前查詢有效,不影響全局。

SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
select * from xxx group by xxx;

參考

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章