sql 除以_刷完这些SQL练习题,简单查询就熟能生巧了

e096be424068f5375ea64eda1ea37e66.png

练习题:SQLZOO

28cafb1b8bfa31d1a7e28c9ad5b7a6db.png

表:(图片未显示全部列)

dfe4c9a6957a1091559e66b8c3acac01.png

(1)SELECT basics:(简单查询)

SELECT basics/zh​sqlzoo.net

①The example uses a WHERE clause to show the population of 'France'. Note that strings (pieces of text that are data) should be in 'single quotes';

Modify it to show the population of Germany

该示例使用WHERE子句显示“法国”的人口。请注意,字符串(作为数据的文本片段)应在“单引号”中;

修改例子,以显示德国的人口

select population
from world
where name='Germany'

②Checking a list The word IN allows us to check if an item is in a list. The example shows the name and population for the countries 'Brazil', 'Russia', 'India' and 'China'.

Show the name and the population for 'Sweden', 'Norway' and 'Denmark'.

检查列表单词IN允许我们检查项目是否在列表中。该示例显示了“巴西”,“俄罗斯”,“印度”和“中国”国家的名称和人口。

显示“瑞典”,“挪威”和“丹麦” 的名称和人口。

select name,population
from world
where name in ('Sweden','Norway','Denmark')

③Which countries are not too small and not too big? BETWEEN allows range checking (range specified is inclusive of boundary values). The example below shows countries with an area of 250,000-300,000 sq. km. Modify it to show the country and the area for countries with an area between 200,000 and 250,000.

哪个国家不太小也不太大? BETWEEN允许范围检查(指定的范围包括边界值)。以下示例显示了面积为250,000-300,000平方公里的国家。对其进行修改以显示该国家/地区以及200,000到250,000之间的国家/地区的面积。

select name,area
from world
where area between 200000 and 250000

43f2ed316da7f87f8557ce72143888c4.png

(2)SELECT from WORLD Tutorial(运算符练习)

SQLZOO:SELECT from WORLD Tutorial/zh​sqlzoo.net

①Observe the result of running this SQL command to show the name, continent and population of all countries.

观察运行此SQL命令的结果,以显示所有国家的名称,大洲和人口。

select name,continent,population
from world

②Show the name for the countries that have a population of at least 200 million. 200 million is 200000000, there are eight zeros.

显示人口至少为2亿的国家/地区的名称。2亿就是200000000,有八个零。

select name
from world
where population>=200000000

③Give the name and the per capita GDP for those countries with a population of at least 200 million.

per capita GDP is the GDP divided by the population GDP/population

找出人口至少为2亿的国家名字和人均GDP。人均GDP是GDP除以人口GDP /人口

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

④Show the name and population in millions for the countries of the continent 'South America'. Divide the population by 1000000 to get population in millions.

查找属于南美洲(South America)的国家名称,并将人口除以100万,以获得数百万人口数。

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

⑤Show the name and population for France, Germany, Italy

查找法国,德国,意大利(France, Germany, Italy)的国家名称和人口

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

⑥Show the countries which have a name that includes the word 'United'

查找国家名称中包含“United”的国家

select name
from world
where name like ‘%United%’

⑦Two ways to be big: A country is big if it has an area of more than 3 million sq km or it has a population of more than 250 million.

Show the countries that are big by area or big by population. Show name, population and area.

两种方式为大:大国是指一个国家面积超过300万平方公里,或者人口超过2.5亿。

找出大国的名称,人口和面积。

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

⑧Exclusive OR (XOR). Show the countries that are big by area (more than 3 million) or big by population (more than 250 million) but not both. Show name, population and area.

找出符合下面条件的国家名称,人口和面积。

条件:人口(大于250000000)或者面积(大于3000000)大的国家,排除同时面积大而且人口大的国家。

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

9b2cef106339b590172fc8df9012950a.png

(3)SELECT names/zh(字符串模糊查询)

SELECT names/zh - SQLZOO​sqlzoo.net

①你可以用WHERE name LIKE 'B%'来找出以 B 为开首的国家。

%是任意字符串。

找出以 Y 字母开头的国家名称。

select name
from world
where name like ‘Y%’

②找出以 Y 字母结尾的国家名称。

select name
from world
where name like ‘%Y’

③“Luxembourg卢森堡”中有一个x字母,还有一个国家的名字中有x。列出这两个国家。

找出所有国家名字中包括字母x。

select name
from world
where name like ‘%x%’

④“Iceland 冰岛”和“Switzerland 瑞士”的名字都是以”land”作结束的。还有其他吗?

找出所有国家,其名字以 land 作结尾。

select name
from world
where name like ‘%land’

⑤“Columbia 哥伦比亚”是以 C 作开始,ia 作结尾的。还有两个国家相同。

找出所有国家,其名字以 C 开始,ia 结尾。

select name
from world
where name like ‘C%ia’

⑥“Greece 希腊”中有双 e 字。哪个国家有双 o 字呢?

找出所有国家,其名字包括字母oo。

select name
from world
where name like ‘%oo%’

⑦“Bahamas 巴哈马”中有三个 a,还有吗?

找出所有国家,其名字包括三个或以上的a。

select name
from world
where name like ‘%a%a%a%’

⑧“India 印度”和”Angola 安哥拉”的第二个字母都是 n。

你可以用底线符_当作单一个字母的字串符。

找出所有国家,其名字以t作第二个字母。

select name
from world
where name like ‘_t%’
order by name

⑨“Lesotho 赖索托”和”Moldova 摩尔多瓦”都有两个字母 o,被另外两个字母相隔着。

找出所有国家,其名字都有两个字母o,被另外两个字母相隔着。

select name
from world
where name like ‘%o__o%’

⑩“Cuba古巴”和”Togo 多哥”都是 4 个字母。

找出所有国家,其名字都是 4 个字母的。

select name
from world
where name like '____'

⑩①“Luxembourg 卢森堡”的首都 capital 都同样叫“Luxembourg”。

查找所有国家的名字,其首都和国家名字是相同的。

select name
from world
where name=capital

a334efb0424fba432397ab96d62b7390.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值