http://zh.sqlzoo.net/wiki/Using_nested_SELECT/zh
1、select name from world
where continent=(select continent from world where name='Brazil')
2、
select name,continent
from world
where continent in (select continent from world where name='Brazil'or name='Mexico')
说明:用了in()语句
3、原题:求中国人口是英国人口的多少倍
解答思路:先查询出英国人口数,再查询出中国人口数,直接采用“/”得出倍数。as语句起到设置别名的作用。
select
population/(select population from world
where name='United Kingdom')
as mul_population
from world
where name='china'
4、原题:找出哪些國家的人口是高於歐洲每一國的人口。
解题思路:先找出所有属于欧洲的国家的人口数,根据题意,“高于欧洲每一国的人口”即当某一国家人口数大于 属于欧洲国家人口数中的最大人口数,则可满足原题中 高于欧洲每一国的人口。
select name from world
where population>(select max(population) from world
where continent='Europe')
或者
SELECT name FROM world
WHERE population > ALL
(SELECT population FROM world
WHERE continent='Europe')
网友评论