当前位置: 移动技术网 > IT编程>数据库>Mysql > linux上,mysql使用聚合函数group by 时报错: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的问题

2018年10月11日  | 移动技术网IT编程  | 我要评论

之前在windows上测试是可以正常使用的,但是上传到linux上后,就报错:

expression #2 of select list is not in group by clause and contains 
nonaggregated column ‘sss.month_id’ which is not functionally 
dependent on columns in group by clause; this is incompatible with 
sql_mode=only_full_group_by

问题出现的原因:
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参考手册”。)

解决方法一:

打开navcat,

用sql查询:

select @@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,重新设置值。

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

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网