繁体   English   中英

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中的示例结果。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM