[英]Query SQL [PSQL]
我需要 SQL 方面的幫助...我想知道是否有可能找到擁有最多球隊數量的國家......國家隊)...
f1 driver ( id_driver , driver_name , team , country )
我設法編寫了給我每個國家的團隊數量的命令(我認為這是正確的)......我不明白如何以及在哪里使用'max'命令......你能幫我嗎?
SELECT (country) ,count(team)
FROM driver
GROUP BY country;
在該解決方案中,您不需要最大值,只需對結果進行排序:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.