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, ...
随机推荐
- C++ ACE 动态加载链接库
添加头文件 #include <ace/DLL.h> #include <ace/DLL_Manager.h> 定义函数接口 typedef long (*PFN_TEST)( ...
- 飞越面试官(一)--Java基础
大家好!我是本公众号唯一官方指定没头屑的小便--怕屁林. 众所周知,现场面试(包括视频面试)多数时候是没有白板,也就是说,对于你的知识点.项目经验.过往经历和个人介绍等等,都是靠一张嘴.所以考虑到这个 ...
- Python3笔记012 - 3.3 条件表达式
第3章 流程控制语句 3.3 条件表达式 在程序开发中,经常会根据表达式的结果,有条件地进行赋值. # 返回两个数中较大的数 a = 10 b = 6 if a>b: r = a else: r ...
- HTTPS协议详解(三):PKI 体系
转自:https://blog.csdn.net/hherima/article/details/52469488 1.RSA身份验证的隐患 身份验证和密钥协商是TLS的基础功能,要求的前提是合 ...
- 听说你还没学Spring就被源码编译劝退了?30+张图带你玩转Spring编译
源码学习第一步,Spring源码编译 之所以写这么一篇文章是因为群里的小伙伴在编译源码时碰到了问题,再加上笔者自身正准备做一个源码的注释版本,恰好也需要重新编译一份代码,至于为什么要将源码编译到本地就 ...
- HDU 5969 最大的位或 (思维,贪心)
HDU 5969 最大的位或 题目大意 B君和G君聊天的时候想到了如下的问题. 给定自然数\(l\)和\(r\) ,选取\(2\)个整数\(x,y\)满足\(l <= x <= y < ...
- Codeforces 1215D Ticket Game 题解
Codeforces 1215D Ticket Game 原题 题目 Monocarp and Bicarp live in Berland, where every bus ticket consi ...
- CentOS7下安装和配置SVN
1. 由于是在CentOS7最小化安装的操作系统环境安装SVN,我们首先排除一些环境因素.在此首先关闭了防火墙,安装了vim文本编辑工具. 2. 使用yum install -y subversi ...
- day77 vue对象提供的属性功能
目录 一.过滤器 二.计算属性(computed) 三.侦听属性(watch) 四.vue对象的生命周期 五.阻止事件冒泡和刷新页面 六.综合案例-todolist 一.过滤器 定义:就是vue允许开 ...
- 目录(Django开发)
python网络编程-socket编程 Django 笔记分享 Django之[基础篇] Django之[进阶篇] Django之 url组件 Django之 Models组件 Django之 adm ...