顯示具有至少2億人口的國家名稱。 2億是200000000,有八個零。

SELECT name FROM world
WHERE population>=200000000

找出有至少200百萬(2億)人口的國家名稱,及人均國內生產總值。

select name ,GDP/population
from world
where population >=200000000

顯示'South America'南美洲大陸的國家名字和以百萬為單位人口數。 將人口population 除以一百萬(1000000)得可得到以百萬為單位人口數。

select name,population/1000000
from world
where continent like 'South America'

顯示法國,德國,意大利(France, Germany, Italy)的國家名稱和人口。

select name,population
from world
where name in('France','Germany','Italy')

顯示包含單詞“United”為名稱的國家。

select name
from world
where name like '%United%'

成為大國的兩種方式:如果它有3百萬平方公里以上的面積,或擁有250百萬(2.5億)以上人口。

select name,population,area
from world
where area>3000000 or population>250000000

美國、印度和中國(USA, India, China)是人口又大,同時面積又大的國家。排除這些國家。顯示以人口或面積為大國的國家,但不能同時兩者。顯示國家名稱,人口和面積。

select name,population,area
from world
where (area>3000000 and population<250000000) or
(area<3000000 and population>250000000)

除以为1000000(6个零)是以百万计。除以十亿(9个零)是以十亿计。使用ROUND函数来显示的数值到小数点后两位。

对于南美显示以百万计人口,以十亿计2位小数GDP。
select name,round(population/1000000,2),round(gdp/1000000000,2)
from world
where continent='South America'

顯示國家有至少一個萬億元國內生產總值(萬億,也就是12個零)的人均國內生產總值。四捨五入這個值到最接近1000。

select name,round(gdp/population,-3)
from world
where gdp>=1000000000000

Show the name - but substitute Australasia for Oceania - for countries beginning with N.

SELECT name,
CASE WHEN continent='Oceania' THEN 'Australasia'
ELSE continent END
FROM world
WHERE name LIKE 'N%'

Show the name and the continent - but substitute Eurasia for Europe and Asia; substitute America - for each country in North America or South America or Caribbean. Show countries beginning with A or B

SELECT name,
CASE WHEN continent IN('Europe','Asia')
THEN 'Eurasia'
WHEN continent IN('North America','South America','Caribbean')
THEN 'America'
ELSE continent END
FROM world
WHERE name LIKE 'A%' OR name LIKE 'B%'

Put the continents right...

  • Oceania becomes Australasia
  • Countries in Eurasia and Turkey go to Europe/Asia
  • Caribbean islands starting with 'B' go to North America, other Caribbean islands go to South America
Show the name, the original continent and the new continent of all countries.
条件嵌套
select name,continent,
case when continent in ('Eurasia', 'Turkey')
then 'Europe/Asia'
when continent = 'Oceania'
then 'Australasia'
when continent = 'Caribbean'
then
case
when name LIKE 'B%'
then 'North America'
else 'South America'
end
else continent end
from world
order by name asc

sqlzoo:2的更多相关文章

  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. Python爬虫之12306-买票器小白源码

    研究不易 import requests import re import urllib.parse import json import datetime from collections impo ...

  2. 第十七节,OpenCV(学习六)图像轮廓检测

    1.检测轮廓 轮廓检测是图像处理中经常用到的,OpenCV-Python接口中使用cv2.findContours()函数查找检测物体的轮廓. cv2.findContours(image, mode ...

  3. 安装spring tool suite时遇到的问题

    首先在Eclipse的市场里没有找到,在官网下载安装包后不能安装,于是找了解决办法,跟安装suite的版本还有关系. 我下的是http://download.springsource.com/rele ...

  4. C++入门篇十一

    单例对象:为了让类只有一个实例,实例不需要自己释放掉 不管创建多少个实例对象进行访问,访问的都是同一个值 #include "pch.h" #include <iostrea ...

  5. vscode 同步配置插件

    目前所用: 1.25.1版本 1,删除 vscode 客户端, 卸载vscode应用软件删除不了用户配置信息,,下载安装还会发现之前下载的插件和个人配置信息都还会重新加载出来 应先彻底清除已安装的插件 ...

  6. 【原创】beyond compare 解决文件一样,对比有差异的问题

    在beyond compare的5~6年的使用过程中突然有一天发现,beyond compare对比的文件都一样,但是却都显示红色!很是烦人. 这是因为beyond compare一开始对比的时时间, ...

  7. oracle Data Modeler 使用教程

    由于 powerdesigner 的版权问题.公司要求集体换成 oracle Data Modeler .免费版就够用,哈哈.这有很详细的入门教程,看一看吧: 官方正版教程 ,特详细,只是英文的,也只 ...

  8. 一次String的错误使用

    今日,在写代码的过程中,程序执行一个方法居然出现了heap space溢出的异常. 从来还没有遇到这样的异常,打断点发现是做字符串拼接时出现此异常. 所以知道了是String使用的异常,因为我做的操作 ...

  9. Mysql-表的完整性约束

    一.概述 为了约束用户对数据增,删,改,以确保数据正确,有效,合规. 有以下几种约束 not null 非空 指定某列不能为空 unique 唯一 指定某列或某几列的组合不能重复 primary ke ...

  10. Zabbix (三)

    一.zabbix支持的主要监控方式: zabbix主要Agent,Trapper,SNMP,JMX,IPMI这几种监控方式,本文章主要通过监控理论和实际操作测试等方式来简单介绍这几种方式的监控原理和优 ...