columnmust appear in the GROUP BY clause or be used in an aggregate function
时间: 2024-04-25 13:24:49 浏览: 136
这个错误是由于在pgsql中,选择显示的字段必须出现在GROUP BY子句中,或者在聚合函数中使用。这是pgsql一个常见的聚合问题。在SQL3标准以前,MySQL允许这样的查询,但在pgsql中会报错。所以在你的查询语句中,如果你想要选择显示cost字段,你需要将它添加到GROUP BY子句中,或者在聚合函数中使用。例如,你可以使用SUM函数来计算总花费,然后将user_name和总花费作为结果显示。这样的查询语句可以是:SELECT user_name, SUM(cost) FROM t_cost GROUP BY user_name。这样就可以避免出现"column must appear in the GROUP BY clause or be used in an aggregate function"的错误了。\[1\]
#### 引用[.reference_title]
- *1* *3* [pgsql报错 must appear in the GROUP BY clause or be used in an aggregate function](https://blog.csdn.net/Programmer_FuQiang/article/details/110483490)[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^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [Postgresql聚合报错:column XXX must appear in the GROUP BY clause or be used in an aggregate function](https://blog.csdn.net/qq_42647903/article/details/127979751)[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^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文