idea报错 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre
程序员文章站
2022-07-15 12:26:46
...
idea报错 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre 如何解决
写了一个查询语句执行的时候,idea日志报错
Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre
在Navicat中执行也会报这个错,查阅了资料,发现是sql_mode的错误
有两种方法解决,其实都是一个操作
方法一(在服务器上直接更改):
在服务器中查询sql_mode
show variables like 'sql_mode';
再重新set sql_mode
set sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
方法二(使用Navicat更改):
1.首先也是在Navicat中查询
select @@global.sql_mode
2.更改sql_mode
set @@global.sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
3.重新使用第一步的查询语句,就发现sql_mode已经更改了
总结:其实这两种方法都是通过修改sql_mode来解决方法了,所以其实是一种。
这个问题出现的原因是因为MySQL 5.7.5及以上功能依赖检测功能。如果启用了ONLY_FULL_GROUP_BY SQL模式(默认情况下),MySQL将拒绝选择列表,HAVING条件或ORDER BY列表的查询引用在GROUP BY子句中既未命名的非集合列,也不在功能上依赖于它们。(5.7.5之前,MySQL没有检测到功能依赖关系,默认情况下不启用ONLY_FULL_GROUP_BY。有关5.7.5之前的行为的说明,请参见“MySQL 5.6参考手册”。)
推荐阅读
-
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains
-
Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column xxxx
-
Mysql数据库报错:select list is not in group by clause and contains .....sql_mode=only_full_group_by问题
-
解决大于5.7版本mysql的分组报错Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated
-
解决大于5.7版本mysql的分组报错Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo.
-
Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregate
-
报错 1055 - Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated
-
1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains解决
-
idea报错 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre
-
linux上,mysql使用聚合函数group by 时报错:SELECT list is not in GROUP BY clause and contains nonaggre的问题