sqlzoo练习记录(SELECT from WORLD Tutorial/zh)

本文记录了在SQLZOO上进行的WORLD Tutorial的SELECT练习,包括从world表中筛选国家名称、人口、GDP等信息,使用WHERE、LIKE、CASE语句进行条件查询,以及对数据进行四舍五入和单位转换的操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

sqlzoo练习记录(SELECT from WORLD Tutorial/zh)

1.閱讀此表的注意事項 觀察運行一個簡單的SQL命令的結果。
SELECT name, continent, population FROM world;

2.如何使用WHERE來篩選記錄。 顯示具有至少2億人口的國家名稱。 2億是200000000,有八個零。
SELECT name FROM world
WHERE population>200000000;

3.找出有至少200百萬(2億)人口的國家名稱,及人均國內生產總值。
SELECT name,gdp/population
FROM world
WHERE population>200000000 ;

4.顯示’South America’南美洲大陸的國家名字和以百萬為單位人口數。 將人口population 除以一百萬(1000000)得可得到以百萬為單位人口數。
SELECT name, population/1000000
FROM world
WHERE continent=‘South America’;

5.顯示法國,德國,意大利(France, Germany, Italy)的國家名稱和人口。
SELECT name,population
FROM world
WHERE name in (‘france’,‘germany’,‘italy’);

6.顯示包含單詞“United”為名稱的國家。
SELECT name
FROM world
WHERE name LIKE ‘%United%’;

7.成為大國的兩種方式:如果它有3百萬平方公里以上的面積,或擁有250百萬(2.5億)以上人口。
展示大國的名稱,人口和面積。
SELECT name,population,area
FROM world
WHERE area>3000000 OR population>250000000;

8.美國、印度和中國(USA, India, China)是人口又大,同時面積又大的國家。排除這些國家。
顯示以人口或面積為大國的國家,但不能同時兩者。顯示國家名稱,人口和面積。
SELECT name,population,area FROM world WHERE (area>3000000 AND population<250000000) OR (area<3000000 AND population>250000000);

9.除以為1000000(6個零)是以百萬計。除以1000000000(9個零)是以十億計。使用 ROUND 函數來顯示的數值到小數點後兩位。
對於南美顯示以百萬計人口,以十億計2位小數GDP。
SELECT name,ROUND(population/1000000,2) ,ROUND(gdp/1000000000,2)
FROM world
WHERE continent=‘South America’;

10.顯示國家有至少一個萬億元國內生產總值(萬億,也就是12個零)的人均國內生產總值。四捨五入這個值到最接近1000。
顯示萬億元國家的人均國內生產總值,四捨五入到最近的$ 1000。
SELECT name,ROUND(gdp/population,-3)
FROM world
WHERE gdp>1000000000000

11.The CASE statement shown is used to substitute North America for Caribbean in the third column.
Show the name - but substitute Australasia for Oceania - for countries beginning with N.
SELECT name,
CASE WHEN continent=‘Caribbean’ THEN ‘North America’
WHEN continent=‘oceania’ THEN ‘Australasia’
ELSE continent END
FROM world
WHERE name LIKE ‘n%’

12.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%’;

13.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 = ‘Oceania’
THEN ‘Australasia’
WHEN continent IN (‘Eurasia’, ‘Turkey’)
THEN ‘Europe/Asia’
WHEN continent = ‘Caribbean’ AND name LIKE ‘B%’
THEN ‘North America’
WHEN continent = ‘Caribbean’ THEN ‘South America’
ELSE continent END
FROM world
ORDER BY name ASC;

quiz:
1.選擇代碼找出以U開頭的國家名稱。
在这里插入图片描述
2.選擇代碼以顯示英國United Kingdom的人口。
在这里插入图片描述
3.這個SQL代碼有什麼錯處。預計結果應該是含’France’的單列。
在这里插入图片描述
4.選擇你會從這個代碼獲得的結果。
在这里插入图片描述
5.選擇代碼以顯示在歐洲和亞洲的國家的名稱和人口。
在这里插入图片描述
6.選擇代碼,結果只有兩列。
在这里插入图片描述
7.選擇你會從這個代碼獲得的結果。
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值