列出每個國家的名字 name,當中人口 population 是高於俄羅斯'Russia'的人口。

SELECT name FROM world
WHERE population >
(SELECT population
FROM world
WHERE name='Russia')

列出歐州每國家的人均GDP,當中人均GDP要高於英國'United Kingdom'的數值。

select name
from world
where continent='Europe' and
gdp/population>(select gdp/population from world
where name='United Kingdom')

在阿根廷Argentina 及 澳大利亞 Australia所在的洲份中,列出當中的國家名字 name 及洲分 continent 。按國字名字順序排序

select name,continent
from world
where continent in(select continent from world
where name in('Argentina','Australia'))
order by name

哪一個國家的人口比加拿大Canada的多,但比波蘭Poland的少?列出國家名字name和人口population 。

select name,population
from world
where population>(select population from world where name='Canada') and
population<(select population from world where name='Poland')

Germany德國(人口8000萬),在Europe歐洲國家的人口最多。Austria奧地利(人口850萬)擁有德國總人口的11%。

顯示歐洲的國家名稱name和每個國家的人口population。以德國的人口的百分比作人口顯示。

小數位數
您可以使用函數ROUND 刪除小數。
百分號 %

select name,concat(round(population*100/(select population from world
WHERE name='Germany'),0),'%')
from world
where continent='Europe'

哪些國家的GDP比Europe歐洲的全部國家都要高呢? [只需列出 name 。] (有些國家的記錄中,GDP是NULL,沒有填入資料的。

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

我們可以在子查詢,參閱外部查詢的數值。我們為表格再命名,便可以分別內外兩個不同的表格。在每一個州中找出最大面積的國家,

列出洲份 continent, 國家名字 name 及面積 area。 (有些國家的記錄中,AREA是NULL,沒有填入資料的。)

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

列出洲份名稱,和每個洲份中國家名字按子母順序是排首位的國家名。(即每洲只有列一國)

select continent,name
from world x
where name=(select name from world y
where y.continent=x.continent
order by name limit 1)

找出洲份,當中全部國家都有少於或等於 25000000 人口. 在這些洲份中,列出國家名字name,continent 洲份和population人口。

select name,continent,population
from world x
where 25000000>all(select population from world y
where y.continent=x.continent
and population>0)

有些國家的人口是同洲份的所有其他國的3倍或以上。列出 國家名字name 和 洲份 continent。

select name,continent
from world x
where population/3>=all(select population from world y
where y.continent=x.continent
and population>0
and y.name!=x.name)

sqlzoo:4的更多相关文章

  1. 练习sql语句的好去处——http://www.sqlzoo.cn/

    sql语句的编写需要按照实际的例子来练习. 如果自己来做准备,需要你自己搭好数据库,建好库和表,还要填入数据,最后自己想出题目和正确答案. 不过,现在我发现了一个好去处,http://www.sqlz ...

  2. sqlzoo练习题答案

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

  3. sqlzoo易错题

    https://sqlzoo.net/wiki/SELECT_names 答案在:https://github.com/codyloyd/sqlzoo-solutions/blob/master/SQ ...

  4. SQLZOO 习题

    https://sqlzoo.net 8. 美國.印度和中國(USA, India, China)是人口又大,同時面積又大的國家.排除這些國家. 顯示以人口或面積為大國的國家,但不能同時兩者.顯示國家 ...

  5. More JOIN operations -- SQLZOO

    The JOIN operation 注意:where语句中对表示条件的需要用单引号, 下面的译文使用的是有道翻译如有不正确,请直接投诉有道 01.List the films where the y ...

  6. The JOIN operation -- SQLZOO

    The JOIN operation 注意:where语句中对表示条件的需要用单引号, 下面的译文使用的是有道翻译如有不正确,请直接投诉有道 01.Modify it to show the matc ...

  7. SUM and COUNT -- SQLZOO

    SUM and COUNT 注意:where语句中对表示条件的需要用单引号, 下面的译文使用的是有道翻译如有不正确,请直接投诉有道 01.Show the total population of th ...

  8. SELECT within SELECT Tutorial -- SQLZOO

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

  9. sqlzoo - SELECT from WORLD Tutorial 答案

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

  10. sqlzoo.net刷题5

    List the continents that have a total population of at least 100 million. 这题考察的是使用集聚函数生成表之后,如何过滤 一般我 ...

随机推荐

  1. 记一场与 cookie 的相遇

    简介: cookie 翻译过来为 “小甜点,一种酥性甜饼干,很美味的...”,咳咳,打住!我们这里说的是 “甜点” 文件,它是浏览器储存在用户电脑上的一小段纯文本格式的文件. 由于 http 是一种无 ...

  2. react 中使用阿里彩色图标

    1. 不光要引入css ,还要引入js 2. 在需要引入icon的地方添加 <svg className={styles.menuIcon} aria-hidden="true&quo ...

  3. 第30月第18天 autolayout代码

    1.上下左右 [tipsLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; { id view1 = tipsLabel; id view2 ...

  4. centos7 安装软件指南

    1. 安装Scrapy: 首先确保依赖已经安装: yum groupinstall -y development tools yum install -y epel-release libxslt-d ...

  5. vs2013、vs2015使用.net4.5框架智能提示英文转成中文

    安装完VS2013.VS2015使用.net framework 4.5框架时,代码补全中智能提示信息全是英文解决方案:关闭VS2013.VS2015:将zh-Hans 目录替换以下目录 C:\Pro ...

  6. ubuntu常用命令及操作,包括安装CUDA

    chmod Document 这里Document是一个文件夹,文件夹中还有好多子文件,可以发现执行了这条指令以后,其子文件夹的权限并没有改变. 要想改变其子文件夹的权限,应该执行 Document/ ...

  7. FTP、FTPS和SFTP

    FTP 一.两种传输方式 ASCII传输方式 假定用户正在拷贝的文件包含的简单ASCII码文本,如果在远程机器上运行的不是UNIX,当文件传输时ftp通常会自动地调整文件的内容以便于把文件解释成另外那 ...

  8. 二十三种设计模式之原型模式的C#实现

    原型模式就是通过拷贝快速创建一个新的对象 本例UML如图 ColorBase [Serializable] public abstract class ColorBase { public int R ...

  9. 将mysql中的一张表中的一个字段数据根据条件导入另一张表中

    添加字段:alter table matInformation add facid varchar(99)  default ''; 导入数据:update matInformation m set ...

  10. mysql 5.7版本后时间datetime 默认为 0000-00-00 00:00:00 问题

    CREATE TABLE `test_user` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` char(25) DEFAULT '' ...