我有一个给定格式的 mysql 表。在这里,我有一个城市和一个参数,如果城市中有足球场,则该参数为真。我想找出每个大陆至少有 2 个城市拥有足球场的国家/地区的百分比。
Id | Stadium| City | Country | Continent
__________________________________________________
1 | true | Manchester | UK | Europe
2 | true | London | UK | Europe
3 | false | Leeds | UK | Europe
4 | true | Berlin | Germany | Europe
5 | false | Dubai | Dubai | Asia
我是 MySQL 的新手。我无法弄清楚如何做到这一点。有人可以帮忙吗。
您可以使用子查询并执行以下操作:
SELECT q.Continent as continent, SUM(IF(q.qntStadiuns > 2, 1, 0))/COUNT(*) * 100 as percent
FROM
(SELECT Continent, Country, COUNT(*) as qntStadiuns
FROM tableName
WHERE Stadium = true
GROUP BY Continent, Country) AS q
GROUP BY continent
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句