问题描述
用mybatis写sql语句的时候,用到了group by关键字,运行报错mysql8.0报错Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘drive.drive_data.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和up实现了对功能依赖的检测。如果启用了only_full_group_by SQL模式(在默认情况下是这样),那么MySQL就会拒绝选择列表、条件或顺序列表引用的查询,这些查询将引用组中未命名的非聚合列,而不是在功能上依赖于它们。
解决办法
打开mysql安装地址的my.ini文件,在尾部添加以下内容,重新启动 mysql 即可:
[mysqld]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION