该得到荣誉却未得到,比不该得到荣誉而得到要好得多。——马克·吐温
今天遇到个报错
发现原来是MYSQL 8
不支持在sql_mode
包含only_full_group_by
时(默认包含)
HAVING
的条件里有 非聚合字段 以外的字段
文档:
Reject queries for which the select list,
HAVING
condition, orORDER BY
list refer to nonaggregated columns that are neither named in theGROUP BY
clause nor are functionally dependent on (uniquely determined by)GROUP BY
columns.A MySQL extension to standard SQL permits references in the
HAVING
clause to aliased expressions in the select list. TheHAVING
clause can refer to aliases regardless of whetherONLY_FULL_GROUP_BY
is enabled.For additional discussion and examples, see Section 12.20.3, “MySQL Handling of GROUP BY”.
解决办法:
打开mysql
的配置文件,修改或添加sql_mode
1 |
|
只要确保没有ONLY_FULL_GROUP_BY
即可