SQL 组合 SELECT 语句(针对 SQL 动物园)
SQL combined SELECT statement (for SQL zoo)
我在使用 SQL zoo 温习 SQL 知识,发现了以下问题:
"Some countries have populations more than three times that of any of
their neighbours (in the same continent). Give the countries and
continents."
我为此制定的解决方案是:
SELECT name, continent
FROM world w
WHERE NOT EXISTS (
SELECT *
FROM world nx
WHERE nx.continent = w.continent
AND nx.population <= 3*w.population)
口译员说我有 "too few columns"(在 number 8 problem on SQL zoo 上)。我不确定这里有什么不正确的地方。任何建议或帮助表示赞赏。
该页面有一个 "Show correct result" 按钮,如果不是您使用的 SQL 语句,它应该会准确告诉您结果的错误之处。
当我使用你的 SQL 语句来解决那个问题时,我得到了正确的列,但是错误的行,所以我必须假设你在某处打字错误。
该问题的一个正确答案是:
SELECT name, continent
FROM world w
WHERE population IS NOT NULL
AND NOT EXISTS (
SELECT * FROM world x
WHERE x.continent = w.continent
AND population IS NOT NULL
AND x.name != w.name
AND x.population > w.population/3
)
我在使用 SQL zoo 温习 SQL 知识,发现了以下问题:
"Some countries have populations more than three times that of any of their neighbours (in the same continent). Give the countries and continents."
我为此制定的解决方案是:
SELECT name, continent
FROM world w
WHERE NOT EXISTS (
SELECT *
FROM world nx
WHERE nx.continent = w.continent
AND nx.population <= 3*w.population)
口译员说我有 "too few columns"(在 number 8 problem on SQL zoo 上)。我不确定这里有什么不正确的地方。任何建议或帮助表示赞赏。
该页面有一个 "Show correct result" 按钮,如果不是您使用的 SQL 语句,它应该会准确告诉您结果的错误之处。
当我使用你的 SQL 语句来解决那个问题时,我得到了正确的列,但是错误的行,所以我必须假设你在某处打字错误。
该问题的一个正确答案是:
SELECT name, continent
FROM world w
WHERE population IS NOT NULL
AND NOT EXISTS (
SELECT * FROM world x
WHERE x.continent = w.continent
AND population IS NOT NULL
AND x.name != w.name
AND x.population > w.population/3
)