首先查看world表的字段:

name continent area population gdp capital tld flag
SELECT * FROM world;

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

SELECT name FROM world
WHERE population >= 200000000;

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

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

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

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

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

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

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

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

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

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

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

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

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);

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';

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

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

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

11、Greece has capital Athens.

Each of the strings 'Greece', and 'Athens' has 6 characters.

Show the name and capital where the name and the capital have the same number of characters.

select name,capital from world where length(name)=length(capital);

12、The capital of Sweden is Stockholm. Both words start with the letter 'S'.

Show the name and the capital where the first letters of each match. Don't include countries where the name and the capital are the same word.
select name,capital from world where left(name,)=left(capital,) and name!=capital;

13、Equatorial Guinea and Dominican Republic have all of the vowels (a e i o u) in the name. They don't count because they have more than one word in the name.

Find the country that has all the vowels and no spaces in its name.

SELECT name
FROM world
where name like '%a%' and name like '%e%' and name like '%i%' and name like '%o%' and name like '%u%' and name not like '% %';

虽然运行正确,但是感觉并不对,后面会找更好的答案解决此问题

总结:

1、round函数的使用

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

2、like操作符

3、XOR操作符(第8题)

4、length函数

用法:

length(str):一个汉字是算三个字符,一个数字或字母算一个字符

char_length: 不管汉字还是数字或者是字母都算是一个字符

5、left

用法:left(str, length),即:left(被截取字符串, 截取长度)

#用法:
left(str, length) #即:left(被截取字符串, 截取长度)
#从右侧截取:
right(str, length) #即:right(被截取字符串, 截取长度)
#截取特定长度字符串
substring(str, pos, length)
#substring(被截取字符串,从第几位开始截取,截取长度)

MySQL练习题--sqlzoo刷题的更多相关文章

  1. MySQL练习题--sqlzoo刷题2

    SELECT from Nobel Tutorial 1.Change the query shown so that it displays Nobel prizes for 1950. SELEC ...

  2. sqlzoo刷题 SELECT from Nobel Tutorial

    SELECT from Nobel Tutorial 1.Change the query shown so that it displays Nobel prizes for 1950. SELEC ...

  3. mysql刷题(不定时更新)

    面试阶段大家基本都会问一些mysql的题,具体的高深理论以后再慢慢补充,但是刷题是不可避免的,下面直接上货 创建/删除表和索引系列 创建表 CREATE TABLE if not exists `te ...

  4. mysql刷题笔记

    近期,为提升自己的工程能力,在休息时常通过刷题来回顾一下基础性知识. 于是选择了牛客网上的mysql知识题库练手,过程中,主要遇到了几个比较有意思的题,记录下来,方便回顾. 题1:SQL29 计算用户 ...

  5. MySQL练习题参考答案

    MySQL练习题参考答案 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号: 思路: 获取所有有生物课程的人(学号,成绩) - 临时表 获取所有有物理课程的人(学号,成绩) - 临时表 根据[ ...

  6. s15day12作业:MySQL练习题参考答案

    MySQL练习题参考答案   导出现有数据库数据: mysqldump -u用户名 -p密码 数据库名称 >导出文件路径           # 结构+数据 mysqldump -u用户名 -p ...

  7. python 全栈开发,Day65(MySQL练习题,参考答案)

    一.MySQL练习题 一.表关系 请创建如下表,并创建相关约束 二.操作表 1.自行创建测试数据 2.查询“生物”课程比“物理”课程成绩高的所有学生的学号.ps:针对的是自己的生物成绩比物理成绩高,再 ...

  8. 湾区求职分享:三个月刷题拿到 Google offer,欢迎踊跃提问

    本文仅以个人经历和个人观点作为参考.如能受益,不胜荣幸. 本文会不断的修正,更新.希望通过大家的互动最后能写出一份阅者受益的文章. 本文纯手打,会有错别字,欢迎指出,虚心接受及时更改. 小马过河,大牛 ...

  9. mysql 练习题答案

    一 题目 1.查询所有的课程的名称以及对应的任课老师姓名 2.查询学生表中男女生各有多少人 3.查询物理成绩等于100的学生的姓名 4.查询平均成绩大于八十分的同学的姓名和平均成绩 5.查询所有学生的 ...

随机推荐

  1. SET SESSION AUTHORIZATION - 为当前会话设置会话用户标识符和当前用户标识符

    SYNOPSIS SET [ SESSION | LOCAL ] SESSION AUTHORIZATION username SET [ SESSION | LOCAL ] SESSION AUTH ...

  2. CWinThread 日志系统

    CWinThread 日志系统 CWinThread 上继承写入日志 CStdioFile 继承文件

  3. json 文件打读取

    1.获取文件路径 /* * BookController.class.getClassLoader().getResource("static/json/book_nav.json" ...

  4. python 在图像上写中文字体 (python write Chinese in image)

    本人处理图像的时候经常使用opencv的包,但是 cv2.putText 显示不了中文,所以查找了如何在python在图像上写中文的方法,在伟大的Stack Overflow上面找到一个方法,分享给大 ...

  5. 【集群】Redis哨兵(Sentinel)模式

    主从切换技术的方法是:当主服务器宕机后,需要手动把一台从服务器切换为主服务器,这就需要人工干预,费事费力,还会造成一段时间内服务不可用.这不是一种推荐的方式,更多时候,我们优先考虑哨兵模式. 一.哨兵 ...

  6. delphi 将Dll等生成资源文件

    资源文件一般为扩展名为res的文件,其自带的资源编译工具BRCC32.EXE(位于/Delphi/BIN目录下) 1.编写rc脚本文本用记事本或其它文本编辑器编写一个扩展名为rc的文件,格式分别为在资 ...

  7. [CSP-S模拟测试]:世界线(DFS+bitset)

    题目描述 时间并不是一条单一的线,而是有许多世界线构成的流. 在一些时刻,世界线会发生分裂:同样的,它们也有可能在一些时刻收束在一起.如果将这些时刻抽象成点,那么这些世界线构成的网络,实际上是一张有向 ...

  8. mysql全家桶(四)存储过程

    一.存储过程1.介绍简单的说,就是一组SQL语句集,功能强大,可以实现一些比较复杂的逻辑功能,类似于JAVA语言中的方法: 存储过程(Stored Procedure)是一种在数据库中存储复杂程序,以 ...

  9. 20175203 2018-2019-2《Java程序设计》第五周学习总结

    20175203 2018-2019-2<Java程序设计>第五周学习总结 第六章:接口与实现 本周学习了<Java程序设计>第六章的内容:接口与实现,以下为本周学习总结. 知 ...

  10. tomcat7以下线程控制

    web server允许的最大线程连接数还受制于操作系统的内核参数设置,通常Windows是2000个左右,Linux是1000个左右. 1.编辑tomcat安装目录下的conf目录下的server. ...