This tutorial looks at how we can use SELECT statements within SELECT statements to perform more complex queries.

name continent area population gdp
Afghanistan Asia 652230 25500100 20343000000
Albania Europe 28748 2831741 12960000000
Algeria Africa 2381741 37100000 188681000000
Andorra Europe 468 78115 3712000000
Angola Africa 1246700 20609294 100990000000
...

1、

List each country name where the population is larger than that of 'Russia'.

world(name, continent, area, population, gdp)
SELECT name FROM world
WHERE population >
(SELECT population FROM world
WHERE name='Russia')

2、Show the countries in Europe with a per capita GDP greater than 'United Kingdom'.
SELECT name FROM world
WHERE gdp/population >
(SELECT gdp/population FROM world
WHERE name='United Kingdom') and continent='Europe'

3、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

4、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') order by name

5、

Germany (population 80 million) has the largest population of the countries in Europe. Austria (population 8.5 million) has 11% of the population of Germany.

Show the name and the population of each country in Europe. Show the population as a percentage of the population of Germany.

Decimal places
Percent symbol %
select name,CONCAT(ROUND(100*population/(select population from world where name='Germany')),'%') from world where continent='Europe'

6、Which countries have a GDP greater than every country in Europe? [Give the name only.] (Some countries may have NULL gdp values)

select name from world where gdp > ALL(select gdp from world where gdp > 0 and continent='Europe')

7、Find the largest country (by area) in each continent, show thecontinent, the name and the area:

SELECT continent, name, area FROM world x
WHERE x.area >=
ALL(SELECT y.area FROM world y
WHERE y.continent=x.continent
AND area>0)

8、List each continent and the name of the country that comes first alphabetically.

 select continent,name from world x where x.name=(select y.name from world y where y.continent=x.continent order by name limit 1)
9、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.
SELECT name, continent, population FROM world x
WHERE 25000000>=ALL (SELECT population FROM world y
WHERE x.continent=y.continent
AND population>0)
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 x.continent=y.continent and x.name!=y.name and y.population>0)

sqlzoo练习答案--SELECT within SELECT Tutorial的更多相关文章

  1. sqlzoo - SELECT from WORLD Tutorial 答案

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

  2. SELECT within SELECT Tutorial -- SQLZOO

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

  3. sqlzoo刷题 SELECT from Nobel Tutorial

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

  4. SELECT from Nobel Tutorial

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

  5. sqlzoo练习题答案

    title: SQL-Learning date: 2019-03-12 20:37:21 tags: SQL --- 这是关于在一个SQL学习网站的练习题答案记录:SQL教程 SQL基础 由一些简单 ...

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

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

  7. PHP MySQL Select 之Select

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

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

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

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

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

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

随机推荐

  1. unnamed not found for the web module

    intellij idea tomcat 启动报错not found for the web module 使用intellij idea 创建tomcat项目的时候会出现该错误: 启动tomcat的 ...

  2. WCF未找到终结点

    配置都配了,仍然找不到,config文件没有重新加载,原因不详,只能重新编译一下,就好了....后续找找原因看看

  3. 5. COLUMNS

    5. COLUMNS 表COLUMNS提供表中列的信息. INFORMATION_SCHEMA Name SHOW Name Remarks TABLE_CATALOG TABLE_SCHEMA TA ...

  4. 条款10:令operator=返回一个reference to * this(Have assignment operators return a reference to *this)

    NOTE: 1.令赋值(assignment)操作符返回一个reference to *this. 2.此协议适用于所有赋值相关的运算比如:+= -= *=....

  5. xshell连接Linux(centos6.8)失败的解决方法

    注意:本人使用的是Centos6.8版本. Centos7以上版本linux命令会又不一样的地方. 启动xshell终端进行连接服务器:使用命令:ssh + ip地址或是手动使用可视化操作窗口操作, ...

  6. Django框架基础知识10-内置分页系统

    from django.shortcuts import render, redirect, reversefrom datetime import datetime# Create your vie ...

  7. LeetCode(237)Delete Node in a Linked List

    题目 Write a function to delete a node (except the tail) in a singly linked list, given only access to ...

  8. 基于 NodeJs 打造 Web 在线聊天室

    Socket.IO 简介与基础环境搭建 任务时间:10min ~ 20min 关于 Socket.IO Socket.IO 可以实现在浏览器和服务器之间实时双向通信,本节课程将详细介绍 Socket. ...

  9. Java学习之正则表达式

    Java正则表达式字符串模式. 正则表达式可以用来搜索.编辑和处理文本. 正则表达式不尽限于一种语言,但在每一种语言中又细微的差别. java.util.regex包中主要有这3个类: Pattern ...

  10. python--如何在线上环境优雅的修改配置文件?

    1.如何在线上环境优雅的修改配置文件? 原配置文件 #原配置文件 global log 127.0.0.1 local2 daemon maxconn 256 log 127.0.0.1 local2 ...