使用GROUP BY 发生错误 SELECT list is not in GROUP BY clause .......... 解决

2022-09-11 12:52:19 浏览数 (1)

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.w.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

在使用GROUP BY对Mysql的数据表进行查询时如果出现以下错误 1.查询mysql 相关mode select @@global.sql_mode; 可以看到模式中包含了ONLY_FULL_GROUP_BY,只要没有这个配置即可。 我的Mysql版本是5.7.23,默认是带了ONLY_FULL_GROUP_BY模式。 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 解决方法一: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';

解决方法2: 打开mysql配置文件:my.cnf或者my.ini,直接选择打开mysql配置文件,然后在[mysqld]下面添加 sql_mode=ONLY_FULL_GROUP_BY,NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,ANSI_QUOTES 重启mysql即可

0 人点赞