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. vim常用指令参考

    (完)

  2. efcore 跨表查询,实现一个接口内查询两个不同数据库里各自的表数据

    最近有efcore跨库查询的需求,研究了下colder框架里文档的分库实现,发现并不能完全实现一个接口下的跨库查询请求,只能满足一个业务层构造指定的唯一一个数据库访问接口. 先说下文档是怎么实现的 D ...

  3. 一文搞定 Spring Data JPA

    Spring Data JPA 是在 JPA 规范的基础上进行进一步封装的产物,和之前的 JDBC.slf4j 这些一样,只定义了一系列的接口.具体在使用的过程中,一般接入的是 Hibernate 的 ...

  4. Github Actions简单部署一个vue/react项目

    大体介绍 本文对github actions部署前端项目做一个简单的总结,总体来说,我感觉用它想要部署一个前端项目,可以说非常简单,简单得令人震惊

  5. 07 Vue常见插件

    项目功能插件 1.vue-router { path: '/', name: 'home', // 路由的重定向 redirect: '/home' } { // 一级路由, 在根组件中被渲染, 替换 ...

  6. scala 数据结构(五):队列 Queue

    1 队列 Queue-基本介绍 队列的说明 1)队列是一个有序列表,在底层可以用数组或是链表来实现. 2)其输入和输出要遵循先入先出的原则.即:先存入队列的数据,要先取出.后存入的要后取出 3)在Sc ...

  7. flask 源码专题(四):wtforms Form实例化流程以及csrf验证

    class LoginForm(Form): #首先执行后得到的结果是UnboundField()对象 name=simple.StringField( label='用户名', validators ...

  8. Flask 基础组件(九):请求扩展

    #!/usr/bin/env python # -*- coding:utf-8 -*- from flask import Flask, Request, render_template app = ...

  9. Python之class面向对象(基础篇)

    概述 面向过程:根据业务逻辑从上到下写垒代码 函数式:将某功能代码封装到函数中,日后便无需重复编写,仅调用函数即可 面向对象:对函数进行分类和封装,让开发“更快更好更强...” 面向过程编程最易被初学 ...

  10. JSON基础使用详解

    JSON:JavaScript对象表示法 1.1 JSON说明 曾经一段时间,XML是互联网传递数据的统一标准,但是业界一直不乏质疑XML的人士,他们都认为XML过于繁琐,冗长:提取数据也过于麻烦 2 ...