我正在尝试SQLZoo的SELECT within SELECT tutorial的问题5


哪些国家的GDP高于欧洲任何国家? [只给名字。]


这是我的解决方案,不正确,但是我不明白为什么。

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


我做错了什么?

最佳答案

select name,gdp from world x where gdp > all (select gdp from world y where continent = "europe" and gdp > 0)


您缺少NULL值检查,因为如果为null值,将获取未知结果,请参见ref:http://dev.mysql.com/doc/refman/5.5/en/all-subqueries.html

测试查询时,某些欧洲国家/地区的world表可能具有空值,因此最好进行检查以避免空值。

关于sql - 查找GDP大于一组国家的国家,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16622642/

10-12 07:35