and contains nonaggregated column
时间: 2023-09-28 15:08:03 浏览: 92
解决大于5.7版本mysql的分组报错Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated
5星 · 资源好评率100%
报错信息中的"and contains nonaggregated column"是指在ORDER BY子句中包含了非聚合列。这个错误通常出现在MySQL版本5.7.5以后,默认启用了ONLY_FULL_GROUP_BY模式,要求在GROUP BY查询中,SELECT语句中的非聚合列必须包含在GROUP BY子句中。
解决这个问题的方法有两种:
1. 修改sql_mode: 可以将sql_mode设置为除了only_full_group_by以外的模式。可以通过执行"SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));"来修改全局模式,或者可以在连接数据库时,添加"sql_mode='非only_full_group_by模式'"的参数来临时修改模式。
2. 修改查询语句: 如果查询中的非聚合列不需要在GROUP BY子句中,可以将其改为聚合函数,如使用MAX()、MIN()、SUM()等函数对该列进行聚合。
以上是解决报错信息"and contains nonaggregated column"的两种方法,请根据具体情况选择合适的方法来解决该问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [MySQL异常:[Err] 1055 – Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nona...](https://download.csdn.net/download/weixin_38742656/13685329)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [解决MySQL报错:1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column ‘in...](https://blog.csdn.net/HaHa_Sir/article/details/80503601)[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^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文