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. web图片前端裁剪功能实现_利用html5 canvas技术实现图片裁剪

    用户上传头像然后截图的需求很常见,很多做法是把图像发送到后端,把裁剪后的结果发送给浏览器,这种方式会增加处理时延.最近正好学习了HTML5里的canvas,发现它的图片处理功能比较强大,就打算用can ...

  2. 编写优秀CSS代码的8个策略

    编写基本的CSS和HTML是我们作为Web开发人员学习的首要事情之一.然而,我遇到的很多应用程序显然没有人花时间真正考虑前端开发的长久性和可维护性. 我认为这主要是因为许多开发人员对组织CSS / H ...

  3. 常用API - Arrays、Math、Object

    Arrays类 概述 此类包含用来操作数组(比如排序和搜索)的各种方法.此类还包含一个允许将数组作为列表来查看的静态工厂. 除非特别注明,否则如果指定数组引用为 null,则此类中的方法都会抛出 Nu ...

  4. 基础设计模式-02 UML图

    在学习设计模式的时候,经常会涉及到类,接口之间关系的梳理,UML图就是一个很好的方式: 1.类,抽象类,接口 类: 抽象类: 接口: 1.抽象类斜体表示: 2.“+”表示public,"-& ...

  5. STA树的深度(树型DP)

    STA树的深度 题目大意 给出一个N个点的树,找出一个点来,以这个点为根的树时,所有点的深度之和最大 Input 给出一个数字N,代表有N个点.N<=1000000 下面N-1条边. Outpu ...

  6. 线下---复习day04

    目录 1 Django与Ajax 2分页器组件 3 forms组件 4cookie与session组件 5中间件组件 6Auth模块 作业: 1 Django与Ajax # 通过ajax向https: ...

  7. 深入Mybatis源码——执行流程

    前言 上一篇分析Mybatis是如何加载解析XML文件的,本篇紧接上文,分析Mybatis的剩余两个阶段:代理封装和SQL执行. 正文 代理封装 Mybatis有两种方式调用Mapper接口: pri ...

  8. C++敲代码前的准备工作

    #pragma GCC target("avx,sse2,sse3,sse4,popcnt") #pragma GCC optimize("O2,Ofast,inline ...

  9. 数据可视化之DAX篇(十一)Power BI度量值不能作为坐标轴?这个解决思路送给你

    https://zhuanlan.zhihu.com/p/79522456 对于PowerBI使用者而言,经常碰到的一个问题是,想把度量值放到坐标轴上,却发现无法实现.尤其是初学者,更是习惯性的想这么 ...

  10. Django框架03 /视图相关

    Django框架03 /视图相关 目录 Django框架03 /视图相关 1. 请求相关 2.响应相关 3.FBV和CBV 视图(视图函数和视图类) 3.1 类视图 CBV 3.2 视图函数 FBV ...