SQL SELECT 个城市
SQL SELECT Cities
我有作业要写一个 SQL 查询:
- 选择所有城市居民(人口)总数大于400的国家
- 选择完全没有建筑物的国家名称。
有一个表定义
我)
SELECT c1.Name
FROM Country c1
JOIN City c2 ON (c1.CountryID = c2.CountryID)
WHERE NOT EXISTS
(SELECT *
FROM City
WHERE Population < 400)
;
为什么这不正确?我没有收到任何记录。
有几种方法,第一种情况适用于此方法:
select *
from Country co
where 400 < all (
select ci.Population
from City ci
where ci.CountryID = co.CountryID
)
第二种情况:
select *
from Country co
where 0 = (
select COUNT(1)
from City ci
JOIN Building B ON B.CityID = CI.CityID
where ci.CountryID = co.CountryID
)
我有作业要写一个 SQL 查询:
- 选择所有城市居民(人口)总数大于400的国家
- 选择完全没有建筑物的国家名称。
有一个表定义
我)
SELECT c1.Name
FROM Country c1
JOIN City c2 ON (c1.CountryID = c2.CountryID)
WHERE NOT EXISTS
(SELECT *
FROM City
WHERE Population < 400)
;
为什么这不正确?我没有收到任何记录。
有几种方法,第一种情况适用于此方法:
select *
from Country co
where 400 < all (
select ci.Population
from City ci
where ci.CountryID = co.CountryID
)
第二种情况:
select *
from Country co
where 0 = (
select COUNT(1)
from City ci
JOIN Building B ON B.CityID = CI.CityID
where ci.CountryID = co.CountryID
)