JAVA错误: Expression #3 of SELECT list is not in GROUP BY

详细错误:

在浏览器请求接口时
There was an unexpected error (type=Internal Server Error, status=500). could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
查看console中错误:
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

错误原因:对于GROUP BY聚合操作,如果在SELECT中的列,没有在GROUP BY中出现,那么这个SQL是不合法的;
解决办法:1、检测MySQL版本:select @@version;(我的MySQL版本是5.7.24)
2、(关掉ONLY_FULL_GROUP_BY),输入命令
一、

set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

3、重启MySQL(很重要!!!!);
参考:https://blog.csdn.net/yalishadaa/article/details/72861737
https://blog.csdn.net/fansili/article/details/78664267

你可能感兴趣的:(JAVA错误: Expression #3 of SELECT list is not in GROUP BY)