该得到荣誉却未得到,比不该得到荣誉而得到要好得多。——马克·吐温
今天遇到个报错

发现原来是MYSQL 8不支持在sql_mode包含only_full_group_by时(默认包含)
HAVING的条件里有 非聚合字段 以外的字段
文档:
Reject queries for which the select list,
HAVINGcondition, orORDER BYlist refer to nonaggregated columns that are neither named in theGROUP BYclause nor are functionally dependent on (uniquely determined by)GROUP BYcolumns.A MySQL extension to standard SQL permits references in the
HAVINGclause to aliased expressions in the select list. TheHAVINGclause can refer to aliases regardless of whetherONLY_FULL_GROUP_BYis enabled.For additional discussion and examples, see Section 12.20.3, “MySQL Handling of GROUP BY”.
解决办法:
打开mysql的配置文件,修改或添加sql_mode
1 | |
只要确保没有ONLY_FULL_GROUP_BY即可