this is incompatible with sql_mode=only_full_group_by

报错信息:

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'xxxx' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

原因:

这是因为mysql5.7及以上版本的mysql中,对于 group by 的这种聚合操作,如果在select 中的列,

没有在group by 中出现,那么这个SQL是不合法的,因为列不在group by的从句中,所以对于设置了这个mode的数据库,在使用group by 的时候,就要用MAX(),SUM(),ANT_VALUE()的这种聚合函数,才能完成GROUP BY 的聚合操作。

解决方法:

1、首先查询你的数据库是否包含:only_full_group_by

select @@global.sql_mode

2、如果包含接着下面的步骤,修改my.cnf

vim my.cnf

找到sql_mode 去掉only_full_group_by

如果没有sql_mode 追加如下代码:

sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

3、重启mysql

systemctl restart mysqld

相关推荐
聆听。。花开雨落6 小时前
mybatis的typeHandler 作用
数据库·mybatis
pxzsky6 小时前
PG17数据库安装中分分词插件:pg_jieba
数据库·postgresql·pg_jieba
她说可以呀7 小时前
Redis哨兵
数据库·redis·bootstrap
霸道流氓气质7 小时前
KMS 密钥管理服务(Key Management Service)原理与实践
linux·服务器·数据库
kirs_ur7 小时前
CXL(Compute Express Link)— 内存扩展的未来
服务器·数据库·性能优化
MonolithIoT9 小时前
实战方案|设备备件无人值守仓库:连续化产线运维备件 7×24 小时数字化管控方案
运维·网络·数据库
瞬间&永恒~9 小时前
【MySQL】4-6:在同一个主机上使用 systemd 运行多个 MySQL服务器
服务器·数据库·mysql
心机之蛙qee9 小时前
Redis的主从、哨兵及集群
数据库·redis·缓存
gwf21610 小时前
磨损均衡算法(Wear Leveling)——SSD如何让每块闪存“公平退休“?
运维·数据库·人工智能·python·嵌入式硬件·算法·智能硬件