解决大于5.7版本mysql的分组报错Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated
程序员文章站
2022-05-31 16:49:56
原因:
mysql 5.7.5和up实现了对功能依赖的检测。如果启用了only_full_group_by sql模式(在默认情况下是这样),那么mysql就会拒绝选择列表、条...
原因:
mysql 5.7.5和up实现了对功能依赖的检测。如果启用了only_full_group_by sql模式(在默认情况下是这样),那么mysql就会拒绝选择列表、条件或顺序列表引用的查询,这些查询将引用组中未命名的非聚合列,而不是在功能上依赖于它们。(在5.7.5之前,mysql没有检测到功能依赖项,only_full_group_by在默认情况下是不启用的。关于前5.7.5行为的描述,请参阅mysql 5.6参考手册。)
执行以下个命令,可以查看 sql_mode 的内容:
mysql> show session variables; mysql> show global variables; mysql> select @@sql_mode;
可见session和global 的sql_mode的值都为:
only_full_group_by,strict_trans_tables,no_zero_in_date,no_zero_date,error_for_division_by_zero,no_auto_create_user,no_engine_substitution
only_full_group_by说明:
only_full_group_by :使用这个就是使用和oracle一样的group 规则, select的列都要在group中,或者本身是聚合列(sum,avg,max,min) 才行,其实这个配置目前个人感觉和distinct差不多的,所以去掉就好
解决:
set global sql_mode='strict_trans_tables,no_zero_in_date,no_zero_date,error_for_division_by_zero,no_auto_create_user,no_engine_substitution';<br data-filtered="filtered">set session sql_mode='strict_trans_tables,no_zero_in_date,no_zero_date,error_for_division_by_zero,no_auto_create_user,no_engine_substitution';<br data-filtered="filtered">
总结
以上所述是小编给大家介绍的解决大于5.7版本mysql的分组报错expression #1 of select list is not in group by clause and contains nonaggregated,希望对大家有所帮助
上一篇: C#单位转换器简单案例
推荐阅读
-
解决大于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.
-
解决大于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.