sql - 查询 SQL [PSQL]
问题描述
我需要有关 SQL 的帮助...我想知道是否有可能找到拥有最多球队的国家......国家队)...
f1 driver ( id_driver , driver_name , team , country )
我设法编写了给我每个国家的团队数量的命令(我认为这是正确的)......我不明白如何以及在哪里使用'max'命令......你能帮我吗?
SELECT (country) ,count(team)
FROM driver
GROUP BY country;
解决方案
在该解决方案中,您不需要 max ,只需对结果进行排序:
SELECT (country) ,count(distinct team)
FROM driver
GROUP BY country
order by count(distinct team) DESC
如果你想要拥有最多球队的国家:
SELECT (country) ,count(distinct team)
FROM driver
GROUP BY country
order by count(distinct team) DESC
LIMIT 2
推荐阅读
- python - 使用 Python C 扩展获取当前工作目录
- mysql - My SQL 5.7.33 错误代码 - 1126。无法打开共享库
- firebase - 无法在firebase实时数据库中的一个节点中获取一个孩子的所有孩子
- sql - 需要支持将 SQL Server 查询转换为 Oracle
- c# - 如何使用 NPOI C# 包创建数据透视表并保存它?
- python - 使用 split 函数应用:'expand' 是 split() 的无效关键字参数
- python - python/dataframe - 合并重复的行
- sql - Laravel 中的 SQL 查询没有返回正确的结果
- javascript - 标准 DOM 元素事件是否在 DOMContentLoaded 之前触发?
- celery - KeyError 收到未注册的“芹菜”类型的任务,而任务已注册