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, ...
随机推荐
- 简单几步让CentOS系统时间同步
在使用CentOS系统的时候,我们可能会遇到时间不准的问题,那我们如何解决这个我问题呢,下面就来教大家一个CentOS系统时间同步的方法,希望大家可以解决自己所存在的疑问. CentOS系统时间同步的 ...
- (私人收藏)[开发必备]HTML5最全快速查找离线手册(可查询可学习,带实例)
[开发必备]HTML5最全快速查找离线手册(可查询可学习,带实例) HTML5最全快速查找离线手册:https://pan.baidu.com/s/19seE8TJQSx4IsWgXtKQS0Aj9y ...
- (私人收藏)2019WER积木教育机器人赛(普及赛)基础解决方案
2019WER积木教育机器人赛(普及赛)基础解决方案 含地图.基础解决方案.全部路线的往返.详细规则.视频.搭建方案 EV3;乐高;机器人比赛;能力风暴;WER https://pan.baidu.c ...
- 进阿里真的这么难?P8大佬告诉你,你和阿里之间缺的只是这份笔记
一转眼今年已经到六月份了,在这个过去的半年里有人选择了安稳,有的人偏偏不... 最近小编就有个朋友,去面了个[P8 级架构师],也算是摸摸行情,为后面的一些安排提前做好规划~ 先给大家介绍一下我这个朋 ...
- Html5标签——Html5新增标签的含义和使用
HTML 5 是一个新的网络标准,目标在于取代现有的 HTML 4.01, XHTML 1.0 and DOM Level 2 HTML 标准.它希望能够减少浏览器对于需要插件的丰富性网络应用服务(p ...
- gulp之demo
1.安装gulp cnpm install -g gulp; 2.然后还需要在当前目录安装gulp,具体不详,只知道安装了之后会在当前目录下的node_modules下多一个gulp文件夹 cnpm ...
- P1004 方格取数——奇怪的dp
P1004 方格取数 题目描述 设有 \(N\times N\) 的方格图 \((N\leq 20)\),我们将其中的某些方格中填入正整数,而其他的方格中则放入数字 \(0\) .如下图所示(见样例) ...
- PowerJob 的故事开始:“玩够了,才有精力写开源啊!”
本文适合有 Java 基础知识的人群 作者:HelloGitHub-Salieri HelloGitHub 推出的<讲解开源项目>系列.经过几番的努力和沟通,终于邀请到分布式任务调度与计算 ...
- 博弈论 | 详解搞定组合博弈问题的SG函数
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天这篇是算法与数据结构专题的第27篇文章,我们继续深入博弈论问题.今天我们要介绍博弈论当中非常重要的一个定理和函数,通过它我们可以解决许多 ...
- shell专题(三):Shell脚本入门
1.脚本格式 脚本以#!/bin/bash开头(指定解析器) 2.第一个Shell脚本:helloworld (1)需求:创建一个Shell脚本,输出helloworld (2)案例实操: [atgu ...