此教程教我們在SELECT查詢中使用別一個SELECT查詢,進行一些更複雜的查詢。
1.列出每個國家的名字 name,當中人口 population 是高於俄羅斯’Russia’的人口。
select name
from world
where population >(select population from world
where name = 'russia')
2.列出歐州每國家的人均GDP,當中人均GDP要高於英國’United Kingdom’的數值。
select name
from world
where continent = 'Europe' and
GDP/population > (select GDP/population from world
where name = 'United Kingdom')
3,在阿根廷Argentina 及 澳大利亞 Australia所在的洲份中,列出當中的國家名字 name 及洲分 continent 。按國字名字順序排序
select name, continent from world
where continent in(select continent from world
where name in('Argentina','Australia'))
order by name
4,哪一個國家的人口比加拿大Canada的多,但比波蘭Poland的少?列出國家名字name和人口population 。
select name ,population
from world
where
population > (select population from world where name = 'canada')
and
population <(select population from world where name = 'Poland')
5,Germany德國(人口8000萬),在Europe歐洲國家的人口最多。Austria奧地利(人口850萬)擁有德國總人口的11%。
顯示歐洲的國家名稱name和每個國家的人口population。以德國的人口的百分比作人口顯示。
select name,concat(round(population*100/(select population
from world
where name='Germany'),0),'%')
from world
where continent='Europe'