手机刷mysql题_MySQL练习题--sqlzoo刷题

首先查看world表的字段:

namecontinentareapopulationgdpcapitaltldflag

SELECT * FROM world;

20180905191327169674.png

2、显示人口至少为2亿的国家/地区的名称。2亿=200million

SELECT name FROMworldWHERE population >= 200000000;

20180905191328043731.png

3、给出人口至少2亿的国家的名称和人均国内生产总值。

select name,(gdp/population) as per_capita_gdp from world where population>=200000000;

20180905191328215613.png

4、显示continent =‘South America‘的国家的名称和人口。 将人口除以100万,以获得数百万人口,也就是population的单位为百万。

select name,(population/1000000) as population from world where continent=‘South America‘ ;

20180905191328405073.png

5、显示法国,德国,意大利的名称和人口(France、Germany、Italy)

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

#注意

#France、Germany等是以字符串形式出现的,加引号,否则会出错

20180905191328591604.png

6、显示名称中包含“United”字样的国家/地区

select name from world where name like ‘%united%‘;

20180905191328771298.png

7、如果一个国家面积超过300万平方公里,或者人口超过2.5亿,那么这个国家就很大。

按人口显示面积大或面积大的国家。 显示名称,人口和面积。

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

20180905191328925601.png

8、

Exclusive OR (XOR). Show the countries that are big by area or big by population but not both. Show name, population and area.

Australia has a big area but a small population, it should be included.

Indonesia has a big population but a small area, it should be included.

China has a big population and big area, it should be excluded.

United Kingdom has a small population and a small area, it should be excluded.

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

20180905191329078927.png

9、Show the name and population in millions and the GDP in billions for the countries of the continent ‘South America‘. Use the ROUND function to show the values to two decimal places.

For South America show population in millions and GDP in billions both to 2 decimal places.

Millions and billions

Divide by 1000000 (6 zeros) for millions. Divide by 1000000000 (9 zeros) for billions.

select name,round(population/1000000,2) as population,round(gdp/1000000000,2) as gdp from world where continent=‘South America‘;

20180905191329216628.png

10、显示GDP至少为1万亿(100亿,即12个零)的国家的名称和人均GDP。 将此值舍入到最接近的1000。

将万亿美元国家的人均GDP显示为最接近的1000美元。

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

20180905191329347492.png

总结:

1、round函数的使用

20180905191329615081.png

链接:http://www.w3school.com.cn/sql/sql_func_round.asp

2、like操作符

20180905191329736179.png

3、XOR操作符(第8题)

20180905191329984235.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值