错误描述:
mysql_5.7中使用 left join 与 group by 时可能会报错,但语句本身没问题。错误提示如下。
[Err] 1055-Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
错误原因:
在MySQL5.7之后,sql_mode中默认存在ONLY_FULL_GROUP_BY,SQL语句未通过ONLY_FULL_GROUP_BY语义检查所以报错。
以SQL语句select columes from table group by list为例:columns必须是聚集函数或者在group by后的表达式list中,并且list中必须包含主键,否则也会报错。
insert、update、delete语句都会报错(但不影响SQL语句的执行),因为这三种语句执行之前也会执行查询操作。错误解决:
永久解决
1,执行 select @@sql_mode
2,去掉查询结果中的ONLY_FULL_GROUP_BY后再复制,打开mysql的配置文件,将sql_mode的值设为所复制的值
MySQL配置文件的位置:安装版产看启动项的安装目录获取my.ini路径
免安装版一般在根目录下(默认是my-default.ini,必须将名字改为my.ini才能生效)
3,重启mysql服务
原文链接:https://blog.csdn.net/a772304419/article/details/79665315
文件链接:https://share.weiyun.com/5hjiwYW 密码:evxum7