简体   繁体   English

为什么ALL关键字在此查询中不起作用?

[英]Why doesn't ALL keyword work in this query?

I have following SQL query: 我有以下SQL查询:

SELECT 
    name
FROM 
    world
WHERE
    gdp > ALL (SELECT gdp FROM world WHERE continent = 'Europe')

I'm running this query at sqlzoo to find countries that have a GDP greater than every country in Europe. 我正在sqlzoo运行此查询,以查找GDP高于欧洲每个国家的国家。

The expected result is United States, China. 预期的结果是美国,中国。 The ALL keyword is supposed to make > work over a list. ALL关键字应该使>在列表中工作。 It doesn't in this case. 在这种情况下不是。 Why? 为什么?

It does work at least with MySQL. 它至少与MySQL兼容。 But you also have to exclude the countries in Europe that have null GDPs: 但您还必须排除GDP值为空的欧洲国家:

SELECT 
    name
FROM 
    world
WHERE
    gdp > ALL (SELECT gdp FROM world WHERE continent = 'Europe' and gdp is not null)

For achieveing desired result you have to try somthing like this:- 为了获得理想的结果,您必须尝试这样的事情:-

SELECT name 
FROM world 
WHERE gdp > ALL (SELECT MAX(gdp) 
                 FROM bbc 
                 WHERE contintent = 'Europe' 
                 AND gdp IS NOT NULL)

and if no countries have GDP as NULL then you can simply remove IS NULL cond. 如果没有国家将GDP设为NULL则只需删除IS NULL cond。

Hope this can help you. 希望这可以帮到你。

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

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