Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 't.fix_code

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/yanyf2016/article/details/102662876

 报错如下

Expression #1 of SELECT list is not in GROUP BY clause and contains
nonaggregated column ‘t.fix_code’ 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及以上功能依赖检测功能

打开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'

这种方法有个很大的弊端,在mysql重启之后,又还原了,最好就是在my.cnf中设置

[mysqld]
sql_mode='STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
lower_case_table_names=0

之后重启mysql 生效即可

猜你喜欢

转载自blog.csdn.net/yanyf2016/article/details/102662876