[英]Noob Concern: Sub-query calculations
我有一個表bbc,其中包含以下列:
名稱 (指世界特定區域內的國家名稱)
區域 (世界大陸)
人口 (國家名稱字段中的國家人口)我想回答的問題:
問題如下:
“有些國家的人口是其鄰國(在同一地區)的三倍以上。請提供這些國家和地區。”
我在想答案可能是這樣的:
SELECT a.name, a.region FROM bbc AS a
WHERE a.region IN
(
SELECT b.region FROM bbc AS b
GROUP By b.region
HAVING MIN(b.population) < 3*b.population)
但老實說,我在最后一行中輸了它……我不知道如何找到比同地區任何鄰國的三倍還多的計數器! 相當艱難。 O_O
任何和所有幫助將不勝感激。
select
a.name, a.region
from bbc as a
where
a.population >
(
select 3*max(b.population)
from bbc as b
where b.region = a.region and b.name <> a.name
)
Select
a.name,
a.region
From
bbc as a
Where
Not Exists (
Select
'x'
From
bbc as b
Where
a.region = b.region And
a.name != b.name And
a.population < 3 * b.population
)
SELECT name, continent from world x
WHERE (SELECT population from world y
where y.name = x.name
and y.continent = x.continent
and population > 0) > ALL
(SELECT 3*population from world z
where z.continent = x.continent
and z.name != x.name
and population > 0);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.