报错信息:
Expression #1 of SELECT list is not in GROUP BY clause and contains
nonaggregated column ‘数据库名.表名.字段名’ which is not functionally dependent
on columns in GROUP BY clause; this is incompatible with
sql_mode=only_full_group_by
执行sql
select count(id) total,role_name, role_code from develop_team_user_app_role where workspace_code = 'ws_ctkpfdurmw_4990' group by role_code
错误解析:
由于开启了ONLY_FULL_GROUP_BY的设置,如果select 的字段不在 group by 中,并且select 的字段未使用聚合函数(SUM,AVG,MAX,MIN等)的话
(在大于5.7.5版本以后的版本会报错)
查询配置命令:
select @@GLOBAL.sql_mode;
查询结果:
解决方案:
- 编辑my.ini文件,添加配置
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
2.重启mysql服务
其他修改方案:
https://blog.csdn.net/u012660464/article/details/113977173