gpt4 book ai didi

mysql - 基于另一个聚合函数结果的 SQL 聚合函数

转载 作者:行者123 更新时间:2023-11-29 12:26:17 25 4
gpt4 key购买 nike

所以真的需要帮助。我需要对计数聚合函数的结果应用最大聚合函数,但我使用的查询一直失败。我有两列:总统(列出总统姓名),国家(列出国家名称);表名佣金。我需要找到总统数量最多的国家。

Select country, count(president) as number_of_presidents 
from commission where country=any(select max(number_of_president)
from commission)
group by country;

非常感谢任何帮助!谢谢

最佳答案

改用Top 1

Select Top 1 country, count(president) as number_of_presidents 
from commission
group by country
Order by number_of_presidents desc

如果您使用Mysql,请删除TOP 1,将order by更改为

Order by number_of_presidents desc limit 1

关于mysql - 基于另一个聚合函数结果的 SQL 聚合函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28262908/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com