java.sql.SQLSyntaxErrorException: this is incompatible with sql

java.sql.SQLSyntaxErrorException: this is incompatible with sql,第1张

java.sql.SQLSyntaxErrorException: this is incompatible with sql

nested exception is java.sql.SQLSyntaxErrorException: expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘t.id’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

sql报这个错是因为,sql语句进group by 查询时,有字段不在group by 导致报错.
修改一下mysql配置即可.
方案一: 临时修改

-- 通过该语句查询 可以发现结果存在 ONLY_FULL_GROUP_BY 选项
select @@global.sql_mode;
-- 进行修改即可
set @@global.sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

方案二:
进入my.ini中进行配置,然后重启mysql即可

# 修改sql_mode配置
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5687111.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-17
下一篇2022-12-17

发表评论

登录后才能评论

评论列表(0条)

    保存