所以真的需要帮助。我需要在count聚合函数的结果上应用max aggregate函数,但是我使用的查询一直都失败了。我有两个栏目:总统(列出总统姓名),国家(列出国家名称);表名委员会。我需要找到拥有最多总统的国家。
Select country, count(president) as number_of_presidents
from commission where country=any(select max(number_of_president)
from commission)
group by country;
任何帮助非常感谢!谢谢
答案 0 :(得分:1)
使用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