需要帮助理解这些 SQL ZOO 查询的元素

need help understanding elements of these SQL ZOO queries

在这两个 sql 动物园问题中,有一个我不理解的 where 子句:

问题 1:

"Some countries have populations more than three times that of all of their neighbors (in the same continent). Give the countries and continents."

答案:

select name, continent
from world x
where population/3 >= ALL(select population from world y where y.continent=x.continent and y.name <> x.name)

问题 2:

Find the continents where all countries have a population <= 25000000. Then find the names of the countries associated with these continents. Show name, continent and population.

答案:

SELECT name, continent, population 
FROM world x 
WHERE 25000000>=ALL (SELECT population FROM world y WHERE x.continent=y.continent AND population>0)

在这两个问题的上下文中,y.continent=x.continent是做什么的?它作为某种连接服务器吗?没有它,查询失败,但我不完全明白为什么。

格式化您的查询,以便您可以更轻松地阅读它并了解正在发生的事情。

select name, 
       continent 
from world x 
where population / 3 >= ALL(select population 
                            from world y 
                            where y.continent=x.continent 
                            and y.name <> x.name)

你的问题是

"Some countries have populations more than three times that of all of their neighbours (in the same continent). Give the countries and continents."

这里有两件事你必须做。你必须得到所有的人口并除以三,然后找到所有等于或大于的人口。那些将是流行音乐的三倍。

x.continent = y.continent 确保您只比较同一大陆上的那些。