select list is not in group clause
时间: 2023-09-04 15:17:35 浏览: 95
如果在MySQL中启用了only_full_group_by SQL模式,那么当查询中的选择列表、条件或顺序列表引用了组中未命名的非聚合列时,MySQL将拒绝执行这些查询,而不是依赖于它们的功能。(在5.7.5之前,MySQL没有检测到这个错误)。
举个例子,如果我们有以下SQL语句:select a, b, sum(c) from 'table_test' group by b;在这种情况下,如果没有使用方法来设置,也会导致报错,因为在MySQL中,如果使用了group by条件,查询中的列如果没有使用聚合函数,都需要放在group by子句中。所以我们可以修改SQL语句为:select a, b, sum(c) from 'table_test' group by a, b;
另一种解决方法是在SQL语句中添加any_value()函数,如下所示:select de.dept_no, max(s.salary) from dept_emp de left join salaries s on de.emp_no = s.emp_no group by de.dept_no;
总而言之,select list is not in group clause这个错误意味着在SQL查询中,选择列表中的列没有放在group by子句中,或者没有使用聚合函数。为了解决这个错误,我们需要将所有未命名的非聚合列都放到group by子句中,或者使用聚合函数来处理这些列。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [解决大于5.7版本mysql的分组报错Expression #1 of SELECT list is not in GROUP BY clause and contains ...](https://download.csdn.net/download/weixin_38743076/13698627)[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】SELECT list is not in GROUP BY clause: mysql数据库异常解决方案](https://blog.csdn.net/dkz97/article/details/106746475)[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* [sql报错SELECT list is not in GROUP BY clause and contains nonaggregated column](https://blog.csdn.net/qq_40262372/article/details/118164265)[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 ]
阅读全文