第2世界
发布于 2026-04-13 / 0 阅读 / 0 评论 / 0 点赞

mysql8 group by 报错

错误:

### Error querying database. Cause: java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'hanzhong-resume-2026-03.box.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by ### The error may exist in file [/home/g01/project/hanzhong-resume-backend-master/material-business/target/classes/mapper/business/custom/BoxInfoCustomMapper.xml] ### The error may involve defaultParameterMap ### The error occurred while setting parameters ### SQL: SELECT count(0) FROM (SELECT box.id, box.code, box.name, count(box.id) quantity, locker.id lockerId, locker.name lockerName, grid.id lockerGridId, grid.name lockerGridName FROM t_box_info box LEFT JOIN t_asset asset ON box.id = asset.box_info_id LEFT JOIN t_locker locker ON locker.id = asset.locker_id LEFT JOIN t_locker_grid grid ON grid.id = asset.locker_grid_id GROUP BY code) table_count ### Cause: java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'hanzhong-resume-2026-03.box.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 'hanzhong-resume-2026-03.box.id' which is not functionally dependent on columns in

解决办法是修改my.cnf在mysqld中增加配置:

sql_mode='NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'


评论