[英]MySQL Comparison Query
I need to compare all regions and show the better regions about the score. 我需要比较所有区域,并显示得分更高的区域。 For example if I want to see Asia's Score Comparison; 例如,如果我想查看亚洲的得分比较; I will see only the better regions about the score. 我只会看到比分更好的区域。 (better regions: North America, Europe) (更好的地区:北美,欧洲)
select
Destination_Region,
count(1) as Score
from pro11
where
Destination_Region is not null
group by
Destination_Region
order by
Score DESC;
Query Result: 查询结果:
Europe 1069737
North America 218302
Asia 140452
Middle East 70899
Africa 33901
Oceania 28701
South America 24815
Caribbeans 16550
So if I want to see Africa's comparison results; 因此,如果我想看看非洲的比较结果; I should see the Middle East, Asia, North America, Europe. 我应该看到中东,亚洲,北美,欧洲。 I will make the query dynamic, you could pick a region and use it. 我将使查询动态化,您可以选择一个区域并使用它。
Thanks! 谢谢!
Check it using HAVING
clause: 使用HAVING
子句检查它:
select
Destination_Region,
count(*) as Score
from pro11
where
Destination_Region is not null
group by
Destination_Region
having Score>(SELECT COUNT(*) FROM pro11 WHERE Destination_Region = 'Africa' GROUP BY Destination_Region)
order by Score DESC;
Sample result in SQL Fiddle . SQL Fiddle中的示例结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.