報錯大概如下:
"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;
參考