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

相关推荐
SelectDB2 分钟前
为什么今天值得重新比较 Apache Doris 和 StarRocks?
大数据·数据库·数据分析
l1258654 分钟前
# LangGraph Deep Research Agent 全流程设计:多轮研究、人机协同与真实来源管理
数据库·人工智能·python·算法·自然语言处理·oracle·langchain
Frank_refuel4 分钟前
MYSQL【进阶】 -> 索引(了解)
数据库·mysql
SelectDB10 分钟前
开源!Apache Doris 上线 Profile 可视化诊断:基于 Doris Skills 破解 AI 误诊难题
数据库·agent·自动化运维
DBA_G10 分钟前
南大通用GBase 8s数据库的“一库三模“
数据库
阿里云大数据AI技术16 分钟前
一套 Spark SQL,打通多种 Catalog:EMR Serverless Spark 统一数据处理实践
人工智能·sql·spark
l1t43 分钟前
DeepSeek总结的DuckDB 如何更快地运行递归 CTE
java·开发语言·数据库·mysql·duckdb
Baron X1 小时前
Redis 7.0.9 完整部署指南
数据库·redis
weixin_440730501 小时前
数据库缓存、索引、缓存命中率的理解
数据库·缓存
DeepAgent2 小时前
AI Agent 工程实践(34):企业 AI Agent 架构
数据库·人工智能·agent