sqlzoo练习答案--SELECT within SELECT Tutorial
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 |
... |
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')
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.
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)
SELECT name, continent, population FROM world x
WHERE 25000000>=ALL (SELECT population FROM world y
WHERE x.continent=y.continent
AND population>0)
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的更多相关文章
- sqlzoo - SELECT from WORLD Tutorial 答案
01.SELECT from WORLD Tutorial 01.显示所有国家的名称,大洲和人口. SELECT name, continent, population FROM world; 02. ...
- SELECT within SELECT Tutorial -- SQLZOO
SELECT within SELECT Tutorial 注意:where语句中对表示条件的需要用单引号, 下面的译文使用的是有道翻译如有不正确,请直接投诉有道 01.List each count ...
- 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 ...
- sqlzoo练习题答案
title: SQL-Learning date: 2019-03-12 20:37:21 tags: SQL --- 这是关于在一个SQL学习网站的练习题答案记录:SQL教程 SQL基础 由一些简单 ...
- 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 * 语句取出表中的所有字段,不论该字段的数据对调用的应用程序是否 ...
随机推荐
- CPP-基础:快速排序
快速排序(Quicksort)是对冒泡排序的一种改进. 它的基本思想是:通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小,然后再按此方法对这两部分数据分 ...
- 暑假集训 || 2-SAT
推荐论文:https://blog.csdn.net/zixiaqian/article/details/4492926 2-SAT问题是2判定性问题,给出n个集合,每个集合中有两个元素,两个元素之一 ...
- QT5:总结篇 控件集合
一.Layouts 二.Spacers 三.Buttons 四.Item Views(Model-Based) 五.Item Widgets(Item-Based) 六.Containers 七.In ...
- ios 自定义delegate(一)
在自定义协议的头文件 .h中 @protocol NSDelegate <NSObject>@optional //可选 - (void)OnOption:(NSString *)pSt ...
- 深搜DFS
POJ-1321 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有 ...
- <Spring Cloud>入门三 Ribbon
1.Ribbon 客户端软负载均衡组件 1.1配置 搭建了三个消费者供客户端调用: 1.修改yml eureka: client: service-url: defaultZone: http://e ...
- Mac 配置 php-fpm
Mac 自带 php-fpm,在终端执行 php-fpm,会报如下错误: ERROR: failed to open configuration file '/private/etc/php-fpm. ...
- MySQL账户管理和主从同步
账户管理 在生产环境下操作数据库时,绝对不可以使用root账户连接,而是创建特定的账户,授予这个账户特定 的操作权限,然后连接进行操作,主要的操作就是数据的CRUD(增删改查) MySQL账户体系:根 ...
- 【C#】【数据结构】001-线性表:顺序表
C#数据结构:顺序表结构 1.自定义顺序表结构 using System.Collections; using System.Collections.Generic; /// <summary& ...
- grunt 使用比较
http://www.cnblogs.com/yexiaochai/p/3603389.html 最全的uglify使用DEMO http://www.cnblogs.com/artwl/p/3449 ...