SQLzoo刷题记录-SELECT within SELECT Tutorial/zh

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。以德國的人口的百分比作人口顯示。 ROUND(7253.86, 1)=7253.9    ROUND(7253.86,-3)=7000   拼接字符串用concat 或者是 | | 

更多 使用方法:mysql中的实现字段或字符串拼接的三种方式_mysql字段拼接_牛奶咖啡13的博客-CSDN博客

select name,concat(round(population/
(select population from world where name='Germany')*100),'%') 
from world where continent='Europe'

6.哪些國家的GDP比Europe歐洲的全部國家都要高呢? [只需列出 name 。] (有些國家的記錄中,GDP是NULL,沒有填入資料的。) 

select name from world 
where gdp> (select max(gdp) from 
world where continent='Europe')

7.在每一個州中找出最大面積的國家,列出洲份 continent, 國家名字 name 及面積 area。 (有些國家的記錄中,AREA是NULL,沒有填入資料的。)  all 可以用对列表内容进行比较。

SELECT continent, name, area FROM world x
  WHERE area>= ALL
    (SELECT area FROM world y
        WHERE y.continent=x.continent
          AND area>0)

8.列出洲份名稱,和每個洲份中國家名字按子母順序是排首位的國家名。(即每洲只有列一國) 

select continent,name from world t
where name <= all (select name from world s where t.continent=s.continent)

9.找出洲份,當中全部國家都有少於或等於 25000000 人口. 在這些洲份中,列出國家名字namecontinent 洲份和population人口。 

select name,continent,population from world t where  25000000 >=all
(select population from world s where t.continent=s.continent)

10.有些國家的人口是同洲份的所有其他國的3倍或以上。列出 國家名字name 和 洲份 continent。

select name,continent from world t where population>= all
(select 3*population from world s 
where t.name!=s.name and t.continent=s.continent)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值