sql查询报错:only_full_group_by解决方案
问题原因:
在 MySQL 5.7 后的版本,当 SQL 语句有 group by 关键词时,有时执行 SQL 会提示如下异常信息:
###
The error occurred while setting parameters
Cause: java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'sanyuan_db.sys_user.user_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'sanyuan_db.sys_user.user_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 版本后默认的 sql 配置是: sql_mode=ONLY_FULL_GROUP_BY,这个配置严格执行了"