SELECT within SELECT Tutorial -- SQLZOO
SELECT within SELECT Tutorial

注意:where语句中对表示条件的需要用单引号, 下面的译文使用的是有道翻译如有不正确,请直接投诉有道
01.List each country name where the population is larger than that of 'Russia'.
译文:列出每个国家的人口超过“俄罗斯”的名字。
select name from world where population>(select population from world where name='Russia' )
02.Show the countries in Europe with a per capita GDP greater than 'United Kingdom'.
译文:显示欧洲国家的人均GDP大于“英国”。
select name from world where continent='Europe' and (GDP/POPULATION)>(select gdp/population from world where name='United Kingdom')
03.List the name and continent of countries in the continents containing either Argentina or Australia. Order by name of the country.
译文:列出包括阿根廷或澳大利亚在内的各大洲的国家名称和大洲。按国家名称排序。
select name,continent from world where continent in (select continent from world where name in('Argentina', 'Australia')) order by name
04.Which country has a population that is more than Canada but less than Poland? Show the name and the population.
译文:哪个国家的人口比加拿大多但比波兰少?显示名字和人口。
select name,population from world where population>(select population from world where name='Canada ') and population<(select population from world where name='Poland')
05.Show the name and the population of each country in Europe. Show the population as a percentage of the population of Germany.
译文:显示欧洲每个国家的名称和人口。显示人口占德国人口的百分比。
# 这题写的有点问题 concat拼接的时候自己在%加上了好多零
SELECT name,concat(round(population/(select population from world where name='Germany'),2)* 100, '%')
FROM world
WHERE continent='Europe'
06.Which countries have a GDP greater than every country in Europe? [Give the name only.] (Some countries may have NULL gdp values)
译文:哪些国家的GDP比欧洲的每个国家都高?只告诉我名字。(有些国家可能有零gdp值)
select name from world where GDP > (select max(GDP) from world where continent='Europe')
07.Find the largest country (by area) in each continent, show the continent, the name and the area:
译文:在每个洲找出最大的国家(按面积),显示洲,名称和地区:
select continent,name,area from world where area in(select max(area) from world group by continent)
08.List each continent and the name of the country that comes first alphabetically.
译文:按字母顺序列出每个洲和国家名称。
SELECT continent,name FROM world a WHERE name <= ALL(SELECT name from world b WHERE a.continent = b.continent )ORDER by name
09.Find the continents where all countries have a population <= 25000000. Then find the names of the countries associated with these continents. Show name, continent and population.
译文:找出所有国家的人口都小于2500亿的大陆。然后找出与这些大陆相关的国家的名字。显示姓名,大陆和人口。
SELECT name,continent,population FROM world x WHERE 25000000 >= ALL(SELECT population FROM world y WHERE y.continent = x.continent)
10.Some countries have populations more than three times that of any of their neighbours (in the same continent). Give the countries and continents.
译文:有些国家的人口是其邻国(在同一大陆)的三倍还多。给出国家和大陆。
SELECT name,continent FROM world x WHERE x.population/3 >= ALL(SELECT population FROM world y WHERE y.continent = x.continent AND y.name != x.name)
练习网址:https://sqlzoo.net/wiki/SELECT_within_SELECT_Tutorial
------------------------------------------------------------------------------------------------------------------------------------------------------------------

SELECT within SELECT Tutorial -- SQLZOO的更多相关文章
- sqlzoo - SELECT from WORLD Tutorial 答案
01.SELECT from WORLD Tutorial 01.显示所有国家的名称,大洲和人口. SELECT name, continent, population FROM world; 02. ...
- sqlzoo刷题 SELECT from Nobel Tutorial
SELECT from Nobel Tutorial 1.Change the query shown so that it displays Nobel prizes for 1950. SELEC ...
- SELECT from Nobel Tutorial
02.SELECT from Nobel Tutorial 注意:where语句中对表示条件的需要用单引号, 下面的译文使用的是有道翻译如有不正确,请直接投诉有道 01.Change the quer ...
- SQL笔记1:SELECT及SELECT高级应用
T-SQL笔记1:SELECT及SELECT高级应用 本章摘要 1:安装AdventureWorks 2:基本运算符和表达式 3:between 4:like 5:escape 6:TOP 7:G ...
- PHP MySQL Select 之Select
从数据库表中选取数据 SELECT 语句用于从数据库中选取数据. 语法 SELECT column_name(s) FROM table_name 注释:SQL 语句对大小写不敏感.SELECT 与 ...
- select * from (select P.*,ROWNUM RN FROM(select * from Mp_Relatedart where pubbaseid=785 order by ID ASC )P)M WHERE M.RN>2 and M.RN <= 7
select * from (select P.*,ROWNUM RN FROM(select * from Mp_Relatedart where pubbaseid=785 order by ID ...
- sql: sybase与oracle中insert into select和select into的用法
1. sybase与oracle中insert into select和select into的用法 http://wjlvivid.iteye.com/blog/1921679 Sybase 一.首 ...
- 关于Select * 与Select 字段名 的问题!
[转]http://blog.csdn.net/tongyu2009/article/details/8252418 1.SELECT * 语句取出表中的所有字段,不论该字段的数据对调用的应用程序是否 ...
- select * 和 select 所有字段的区别
阅读本文大概需要 1 分钟. 之前发过的文章中,关于 select * 和 select 所有字段的知识,有描述不恰当,这次重新纠正下,加深下理解. MySQL 5.1.37 表记录数 41,547, ...
随机推荐
- (私人收藏)java实例、知识点、面试题、SHH、Spring、算法、图书管理系统、综合参考
https://pan.baidu.com/s/1hkmgJU6pf2sBjNV1NlOaNgr6l2 Java趣味编程100例java经典选择题100例及答案java面试题大全java排序算法大全j ...
- (私人收藏)[开发必备]HTML5最全快速查找离线手册(可查询可学习,带实例)
[开发必备]HTML5最全快速查找离线手册(可查询可学习,带实例) HTML5最全快速查找离线手册:https://pan.baidu.com/s/19seE8TJQSx4IsWgXtKQS0Aj9y ...
- CSS粘性定位
粘性定位(position:sticky) 1.定义 粘性定位可以被认为是相对定位和固定定位的混合.元素在跨越特定阈值前为相对定位,之后为固定定位.(MDN传送门) 这个特定阈值指的是 top, ri ...
- rabbitmq部署及配置与验证
1. 场景描述 朋友项目需要弄个测试环境,稍微帮忙了下,系统不复杂,但是需要自己安装mysql.Reids.Es.RabbitMq等,Mq主要用在同步用户信息与发送站内消息和短信上,RabbitMq以 ...
- Jmeter系列(40)- 详解 Jmeter CLI 模式
如果你想从头学习Jmeter,可以看看这个系列的文章哦 https://www.cnblogs.com/poloyy/category/1746599.html 什么是 CLI 模式 CLI = Co ...
- gitlab-ci部署实现持续集成(centos7)
一.gitlab安装 1. 环境准备 // selinux和 firewall 关闭 $ setenforce 0 $ sed -i "/^SELINUX/s/enforcing/disab ...
- java 面向对象(二十三):关键字:abstract以及模板方法的设计模式
abstract abstract: 抽象的1.可以用来修饰:类.方法2.具体的:abstract修饰类:抽象类 * > 此类不能实例化 * > 抽象类中一定有构造器,便于子类实例化时调用 ...
- 数据可视化之powerBI入门(九)PowerBI数据建模:其实一点都不高深
https://zhuanlan.zhihu.com/p/64149834 数据建模并没有那么高深,你同样可以学会!这篇文章通过一个实例创建一个简单的数据建模,并引出两个重要的概念:度量值和DAX. ...
- 阅读手札 | 手把手带你探索『图解 HTTP』
前言 本文已经收录到我的 Github 个人博客,欢迎大佬们光临寒舍: 我的 Github 博客 学习清单: 一.网络基础 TCP/IP 通常使用的网络(包括互联网)是在 TCP/IP 协议族的基础上 ...
- 【软件测试】Python自动化软件测试算是程序员吗?
今天早上一觉醒来,突然萌生一个念头,[软件测试]软件测试算是程序员吗?左思右想,总感觉哪里不对.做了这么久的软件测试,还真没深究过这个问题. 基于,内事问百度的准则: 结果…… 我刚发 ...