group by查询数据库报错
时间: 2023-08-09 18:08:19 浏览: 55
回答: 当使用group by进行分组查询时,如果group by后的字段与select后查询的字段不一致,就会报错。报错信息如下:#1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by。\[1\]这个错误在达梦数据库中也存在。解决这个问题有几种方法。一种是补全group by后的字段,但这种方法不推荐,因为如果要查询的字段很多且内容不能保证不重复,补全所有字段会导致查询数据丢失。另一种方法是修改配置,可以使用navicat管理工具连接mysql数据库,然后在命令界面中输入以下语句来修改配置:select @@global.sql_mode; set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';\[3\]这样就可以解决group by查询数据库报错的问题了。
#### 引用[.reference_title]
- *1* *3* [高版本Mysql使用group by 分组报错](https://blog.csdn.net/qq_43486404/article/details/126744365)[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^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [达梦数据库SQL查询报错不是 GROUP BY 表达式解决方法](https://blog.csdn.net/qq_37898570/article/details/126951104)[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^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]