MySQL 8.0.xx 版本解决group by分组的问题

因为版本升级5.7版本以下是没有这个问题的,8.0版本以上会出现分组问题

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

 我的版本是8.0.34

1、查看是不是存在only_full_group_by

SELECT @@sql_mode;

执行结果:ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

修改掉 ONLY_FULL_GROUP_BY

2、执行

set sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

再去执行就已经没有group by的问题了

你可能感兴趣的:(mysql,数据库)