-- 关闭严格模式
SET sql_mode = '';
-- 开启严格模式
SET sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
严格模式grop by 校验问题:
caused by: java.sql.SQLSyntaxErrorException: Expression #15 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'd.goods_name' which is not functionally
│ at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.30.jar!/:8.0.30]
导致原因:
select xx, yyy , ss from table group by xx
分组查询时,select 后面的分组字段, 没有在group by 后面
解决办法:
-- 修改sql语句, 使用ANY_VALUE() 方法包裹住不在group by 后面的字段即可。
select xx, ANY_VALUE(yyy) yyy , ANY_VALUE(ss) ss from table group by xx