本文作者:DurkBlue

遇到mysql报错#15 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'seata_db.p.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by怎么处理推荐

DurkBlue 2023-10-12 238 抢沙发
遇到mysql报错#15 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'seata_db.p.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by怎么处理摘要: 问题描述查询语句SELECT         f.*, p.id AS...

问题描述

查询语句

SELECT         f.*, p.id AS p_id,         CASE         WHEN p.id IS NOT NULL THEN 1 ELSE 0 END is_use         FROM         lkt_freight AS f         LEFT JOIN lkt_product_list AS p ON p.freight = f.id and p.recycle = 0                    WHERE  f.store_id = ?                 and f.mch_id = ?


结果

SELECT list is not in GROUP BY clause and contains nonaggregated column ‘dt.res.name’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by


遇到mysql报错#15 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'seata_db.p.id' which functionally dependent on columns clause; this incompatible with sql_mode=only_full_group_by怎么处理  第1张


解释

查询的列不是在分组子句子句中,并且包含非聚合的列(dt.res.name)。

这与sql_mode = only_full_group_by 不符合


这么说就理解了,使用group by 语句时,select不应该含有非分组字段。

但是我记得,mysql数据库是可以的啊。sql_mode又是什么呢?


mysql官网对sql_mode解释


遇到mysql报错#15 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'seata_db.p.id' which functionally dependent on columns clause; this incompatible with sql_mode=only_full_group_by怎么处理  第2张


那怪不得会报错!

如何解决呢?


遇到mysql报错#15 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'seata_db.p.id' which functionally dependent on columns clause; this incompatible with sql_mode=only_full_group_by怎么处理  第3张


更改sql_mode 不就行了嘛!

查看sql_mode

select @@sql_mode;1

遇到mysql报错#15 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'seata_db.p.id' which functionally dependent on columns clause; this incompatible with sql_mode=only_full_group_by怎么处理  第4张

更改sql_mode

修改my.ini(win10 mysql7的配置文件)

将only_full_group_by 策略去掉。


第一步

在你安装的mysql目录下找到my.ini(win10),记事本打开加上下面这句。


[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'



第二步重启mysql服务


A: win10 service


遇到mysql报错#15 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'seata_db.p.id' which functionally dependent on columns clause; this incompatible with sql_mode=only_full_group_by怎么处理  第5张


B: cmd命令

使用管理员打开cmd(命令提示符)界面。

运行下面三句话:


>mysqld --insatll
>net stop mysql
>net start mysql


问题解决成功!


此篇文章由DurkBlue博客申请发布,转载吧请注明来处
文章投稿或转载声明

来源:DurkBlue版权归原作者所有,转载请保留出处。本站文章发布于 2023-10-12
温馨提示:文章内容系作者个人观点,不代表DurkBlue博客对其观点赞同或支持。

赞(0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏

阅读
分享

发表评论取消回复

快捷回复:
AddoilApplauseBadlaughBombCoffeeFabulousFacepalmFecesFrownHeyhaInsidiousKeepFightingNoProbPigHeadShockedSinistersmileSlapSocialSweatTolaughWatermelonWittyWowYeahYellowdog

评论列表 (暂无评论,238人围观)参与讨论

还没有评论,来说两句吧...