MySQL 比较查询

MySQL Comparison Query

我需要比较所有区域并显示分数较好的区域。例如,如果我想查看亚洲的分数比较;我只会看到关于分数的更好区域。 (更好的地区:北美、欧洲)

select
    Destination_Region,
    count(1) as Score
from pro11
    where 
        Destination_Region is not null
    group by 
        Destination_Region 
    order by 
        Score DESC;

查询结果:

Europe             1069737
North America      218302
Asia               140452
Middle East        70899
Africa             33901
Oceania            28701
South America      24815
Caribbeans         16550

所以如果我想看非洲的比较结果;我应该看看中东、亚洲、北美、欧洲。我将使查询动态化,您可以选择一个区域并使用它。

谢谢!

使用 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;

示例结果 SQL Fiddle