首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >mysql having报错this is incompatible with sql_mode=only_full_group_by

mysql having报错this is incompatible with sql_mode=only_full_group_by

作者头像
阿超
发布2023-02-21 08:46:00
发布2023-02-21 08:46:00
7760
举报
文章被收录于专栏:快乐阿超快乐阿超

今天遇到个报错

发现原来是MYSQL 8不支持在sql_mode包含only_full_group_by时(默认包含)

HAVING的条件里有 非聚合字段 以外的字段

文档:

  • ONLY_FULL_GROUP_BY Reject queries for which the select list, HAVING condition, or ORDER BY list refer to nonaggregated columns that are neither named in the GROUP 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. The HAVING clause can refer to aliases regardless of whether ONLY_FULL_GROUP_BY is enabled. For additional discussion and examples, see Section 12.20.3, “MySQL Handling of GROUP BY”.

解决办法:

打开mysql的配置文件,修改或添加sql_mode

代码语言:javascript
复制
[mysqld]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

只要确保没有ONLY_FULL_GROUP_BY即可

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-02-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档