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 namecontinent 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的更多相关文章

  1. sqlzoo - SELECT from WORLD Tutorial 答案

    01.SELECT from WORLD Tutorial 01.显示所有国家的名称,大洲和人口. SELECT name, continent, population FROM world; 02. ...

  2. sqlzoo刷题 SELECT from Nobel Tutorial

    SELECT from Nobel Tutorial 1.Change the query shown so that it displays Nobel prizes for 1950. SELEC ...

  3. SELECT from Nobel Tutorial

    02.SELECT from Nobel Tutorial 注意:where语句中对表示条件的需要用单引号, 下面的译文使用的是有道翻译如有不正确,请直接投诉有道 01.Change the quer ...

  4. SQL笔记1:SELECT及SELECT高级应用

      T-SQL笔记1:SELECT及SELECT高级应用 本章摘要 1:安装AdventureWorks 2:基本运算符和表达式 3:between 4:like 5:escape 6:TOP 7:G ...

  5. PHP MySQL Select 之Select

    从数据库表中选取数据 SELECT 语句用于从数据库中选取数据. 语法 SELECT column_name(s) FROM table_name 注释:SQL 语句对大小写不敏感.SELECT 与 ...

  6. 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 ...

  7. sql: sybase与oracle中insert into select和select into的用法

    1. sybase与oracle中insert into select和select into的用法 http://wjlvivid.iteye.com/blog/1921679 Sybase 一.首 ...

  8. 关于Select * 与Select 字段名 的问题!

    [转]http://blog.csdn.net/tongyu2009/article/details/8252418 1.SELECT * 语句取出表中的所有字段,不论该字段的数据对调用的应用程序是否 ...

  9. select * 和 select 所有字段的区别

    阅读本文大概需要 1 分钟. 之前发过的文章中,关于 select * 和 select 所有字段的知识,有描述不恰当,这次重新纠正下,加深下理解. MySQL 5.1.37 表记录数 41,547, ...

随机推荐

  1. Python3笔记002 - 1.2 搭建python开发环境

    第1章 认识python 1.2 搭建python开发环境 1.2.1 python开发环境概述 python开发环境常见的操作系统: Windows Mac OS Linux 1.2.2 安装pyt ...

  2. Cache写策略(Cache一致性问题与骚操作)

    写命中 写直达(Write Through) 信息会被同时写到cache的块和主存中.这样做虽然比较慢,但缺少代价小,不需要把整个块都写回主存.也不会发生一致性问题. 对于写直达,多出来%10向主存写 ...

  3. 小师妹学JVM之:cache line对代码性能的影响

    目录 简介 一个奇怪的现象 两个问题的答案 CPU cache line inc 和 add 总结 简介 读万卷书不如行万里路,讲了这么多assembly和JVM的原理与优化,今天我们来点不一样的实战 ...

  4. 权益质押(Staking):这是关于什么的?

    我们最近发表了三篇讲述Fetch.AI分类帐本的文章.这些概述: 我们的权益质押计划的主要特点和验证器的作用 影响我们设计权益质押模型设计的因素 我们的创新共识协议将如何改变用户体验 这些文章包含大量 ...

  5. pigctf期末测评

    pigctf期末测评 MISC 1 拿到图片,先binwalk一下,如下图 果然发现png图片后面跟了个ZIP,然后提取出来打开发现了一个flag.png,然后查看16进制文件没有发现什么问题,之后查 ...

  6. shell专题(八):read读取控制台输入

    1.基本语法 read(选项)(参数) 选项: -p:指定读取值时的提示符: -t:指定读取值时等待的时间(秒). 参数 变量:指定读取值的变量名 2.案例实操 (1)提示7秒内,读取控制台输入的名称 ...

  7. 07 drf源码剖析之节流

    07 drf源码剖析之节流 目录 07 drf源码剖析之节流 1. 节流简述 2. 节流使用 3. 源码剖析 总结: 1. 节流简述 节流类似于权限,它确定是否应授权请求.节流指示临时状态,并用于控制 ...

  8. Java对象与Json字符串的转换

    Java对象与Json字符串的转换 JSON是一种轻量级的数据交换格式,常用于前后端的数据交流 后端 : 前端 Java对象 > JsonString Java对象 < jsonStrin ...

  9. 微信小程序接口封装、原生接口封装、request、promise封装

    相信大家在做微信小程序的时候会有很多地方需要调用接口,就和pc以及手机端一样,多个页面多次调用会有很多状态,那为了节省大家的开发时间就会需要给请求的接口做一些简单封装,便于开发,在这里我用了两个js, ...

  10. 一张PDF了解JDK10 GC调优秘籍-附PDF下载

    目录 简介 Java参数类型 Large Pages JIT调优 总结 简介 今天我们讲讲JDK10中的JVM GC调优参数,JDK10中JVM的参数总共有1957个,其中正式的参数有658个. 其实 ...