Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 找出GDP大于一组国家的国家_Sql - Fatal编程技术网

Sql 找出GDP大于一组国家的国家

Sql 找出GDP大于一组国家的国家,sql,Sql,我正在尝试SQLZoo的第5个问题 哪些国家的GDP高于欧洲任何国家?[仅提供名称。] 这是我的解决方案,这是不正确的,但我不明白为什么 SELECT name FROM world WHERE gdp > ALL (SELECT gdp FROM world WHERE continent ='Europe') 我做错了什么 SELECT name FROM world WHERE gdp > (SELECT MAX(gdp) FROM world WHE

我正在尝试SQLZoo的第5个问题

哪些国家的GDP高于欧洲任何国家?[仅提供名称。]

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

SELECT name  
  FROM world  
 WHERE gdp > ALL (SELECT gdp FROM world WHERE continent ='Europe')
我做错了什么

SELECT name 
  FROM world 
 WHERE gdp > (SELECT MAX(gdp) FROM world WHERE continent = 'Europe')
使用MAX aggregate函数返回子查询中的最高GDP,这是您希望与外部查询进行比较的结果

select name, gdp 
from world x 
where gdp > all (select gdp from world y where continent = "Europe" and gdp > 0)
您缺少空值检查,因为如果将获取空值未知的结果,请参阅ref:


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

我连续地检查了这些问题,出于某种原因,我想起了上一个问题中的德国。所以我在我的问题中有了这个,并得到了正确的答案。哈哈,试试看。我用的是铬

select name from world 
 where gdp > ALL(select gdp from world 
 where continent = 'Europe' 
   and gdp is not null)
从世界中选择名称 其中gdp>全部 从世界范围内选择gdp 如果name='Germany'和population0

请尝试以下方法:

SELECT name   FROM world  WHERE  gdp>= ALL(select gdp from world where continent='europe' and gdp>=0) and continent !='europe'

因为GDP有一个空值,所以若你们将任何其他值和空值进行比较,那个么答案将是空的

从世界中选择名称 哪里 GDP>ALLSELECT合并GDP,0来自世界大陆=‘欧洲’; 在上面的例子中,如果传递COALESCEGDP,0,这意味着传递的是GDP列,如果GDP中的任何值为Null,则COALESCE函数将返回“0”用户提供的值

将0作为标准值传递以进行比较,因为0是最小值。

尝试以下操作: 我们可以选择最大值,然后应用大于条件

select name from world where gdp > (select max(gdp) from world where continent = 'Europe')

怎么了?你的回答让我很开心。因为rowsOK太少,我一直在想,我使用firefox,它告诉我我的答案是正确的。。。但用铬就不行了我可以写gdp NULL而不是gdp>0吗?虽然只写代码回答可能会解决这个问题,但最好提供一些关于解决方案的解释,以及为什么代码更好,或者代码的哪个部分解决了这个问题。这对其他人也更有帮助,有助于人们学习。