MySQL GROUP BY 出现 sql_mode=only_full_group_by 问题处理

原创
2021/03/17 13:40
阅读数 204

报错大概如下:

"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;

参考

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
0 评论
0 收藏
0
分享
返回顶部
顶部