【MySQL】MySQL异常SELECT list is not in GROUP BY clause and contains nonaggregated column ‘

报错信息

### Cause: java.sql.SQLSyntaxErrorException: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'production_mes2.log_cutpiecequalitytestingrecords.workCellId' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'production_mes2.log_cutpiecequalitytestingrecords.workCellId' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by] with root cause

java.sql.SQLSyntaxErrorException: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'production_mes2.log_cutpiecequalitytestingrecords.workCellId' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) ~[mysql-connector-java-8.0.21.jar:8.0.21]

原因:MySQL5.7多余ONLY_FULL_GROUP_BY的sql_model被禁止使用

解决方案

去掉MySQl5.7的ONLY_FULL_GROUP_BY模式
1、

 SELECT @@GLOBAL.sql_mode;

在这里插入图片描述
2、

set @@GLOBAL.sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

在这里插入图片描述

在这里插入图片描述
3、重新连接数据库

测试

在这里插入图片描述

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
回答: 当使用GROUP BY语句进行查询时,SELECT语句中只能包含GROUP BY后面声明的列或者聚合函数。这是因为MySQL的ONLY_FULL_GROUP_BY模式要求SELECT语句中的列必须是明确的,以确保分组求最值的合法性检查。这种模式采用了与Oracle、DB2等数据库的处理方式。因此,如果在GROUP BY语句中使用了聚合函数,就需要将SELECT语句中的列限制在GROUP BY后面声明的列或者聚合函数中。如果SELECT语句中出现了不明确的列,就会报错"SELECT list is not in GROUP BY clause and contains nonaggregated column"。\[1\]\[2\]\[3\] #### 引用[.reference_title] - *1* [mysql使用group by查询报错SELECT list is not in GROUP BY clause and contains nonaggregated column.](https://blog.csdn.net/weixin_40925480/article/details/127680083)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [mysql使用group by查询报错SELECT list is not in GROUP BY clause and contains nonaggregated column......](https://blog.csdn.net/weixin_37557729/article/details/123896433)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值