1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated
时间: 2023-10-12 14:06:04 浏览: 101
MySQL异常:[Err] 1055 – Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nona…
5星 · 资源好评率100%
引用和中提到的错误信息是MySQL数据库中常见的错误之一,错误代码为1055。该错误通常出现在使用GROUP BY子句时,ORDER BY子句中引用了未包含在GROUP BY子句中的列。这是因为在MySQL的新版本中,默认启用了"only_full_group_by"模式,该模式要求在使用GROUP BY子句时,SELECT语句中的列必须要么在GROUP BY子句中出现,要么作为聚合函数的参数。
要解决这个错误,有以下几种方法:
1. 将ORDER BY子句中的列添加到GROUP BY子句中,以使其包含所有被引用的列。这样可以确保查询结果的正确性,但可能会导致结果不如预期。
2. 在ORDER BY子句中使用聚合函数而不是列名。这样可以绕过only_full_group_by模式的限制,但可能会改变查询结果的排序方式。
3. 修改MySQL的配置文件,将sql_mode参数中的"only_full_group_by"模式移除或修改为其他适合的模式。这样可以全局禁用或修改only_full_group_by模式,但可能会影响其他查询的执行。
需要注意的是,选择哪种方法取决于具体的业务需求和查询的目的。在修改查询语句或MySQL配置之前,建议先仔细分析查询的逻辑和结果,并确保所采取的方法符合预期。<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: 33.333333333333336%"]
- *2* [解决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: 33.333333333333336%"]
- *3* [mysql5.7 group报错ERROR 1055 (42000): Expression #1](https://blog.csdn.net/qq_38157006/article/details/89952307)[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: 33.333333333333336%"]
[ .reference_list ]
阅读全文