name continent area population gdp
Afghanistan Asia 652230 25500100 20343000000
Albania Europe 28748 2831741 12960000000
Algeria Africa 2381741 37100000 188681000000
Andorra Europe 468 78115 3712000000
Angola Africa 1246700 20609294 100990000000
……        

name:国家名称 continent:大洲 area:面积 population:人口 gdp:国内生产总值

一、 SELECT basics

1、显示德国人口

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

SELECT population FROM world
WHERE name='Germany';

2、显示Sweden瑞典,Norway挪威,Denmark丹麦的国家名称和人口

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'.
SELECT name,population FROM world
WHERE name IN ('Sweden','Norway','Denmark');

3、显示面积为200,000及250,000之间的国家名称和该国面积

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.

SELECT name,area FROM world
WHERE area BETWEEN 200000 AND 250000;

二、SELECT from world

1、显示所有国家的名称,所在大洲,人口

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

SELECT name,continent,population
FROM world;

2、显示人口超过2亿的国家名称

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

SELECT name FROM world
WHERE population >= 200000000;

3、显示人口超过2亿的国家名称和人均GDP

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

SELECT name,GDP/population FROM world
WHERE population >=200000000;

下面的表达也是正确的。

4、显示continent ='South America'的国家的名称和人口。

将人口除以100万,以获得数百万人口,也就是population的单位为百万。

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

SELECT name,population/1000000 FROM world
WHERE continent='South America';

5、显示法国、德国、意大利的国家名称和人口。

Show the name and population for France, Germany, Italy

SELECT name,population FROM world
WHERE name IN ('France','Germany','Italy');

6、显示名字中有‘United’的国家名称。

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

SELECT name FROM world
WHERE name LIKE '%United%';

7、Two ways to be big

如果一个国家面积超过300万平方公里,或者人口超过2.5亿,那么这个国家就很大。按人口显示面积大或面积大的国家。 显示国家名称,人口和面积。

SELECT name,population,area FROM world
WHERE area >=3000000 OR population >=250000000;

8、One or the other (but not both)

XOR 国家面积超过300万平方公里,或者人口超过2.5亿的国家,但是不能同时满足。显示国家名称,人口,面积。

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.

  • 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 area >=3000000 XOR population >=250000000;

9、ROUND函数

除以1000000(6个0)是以百万计,除以1000000000(9个0)是以十亿计。

显示南美洲的国家名称,人口,GDP(人口以百万为单位,GDP以十亿为单位);并且用ROUND函数保留两位小数。

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.
SELECT name,ROUND(population/1000000,2),ROUND(GDP/1000000000,2) FROM world
WHERE continent='South America';

10、显示GDP超过1万亿的国家名称和人均GDP,人均GDP用ROUND函数四舍五入到$1000。

Show the name and per-capita GDP for those countries with a GDP of at least one trillion (1000000000000; that is 12 zeros). Round this value to the nearest 1000.

Show per-capita GDP for the trillion dollar countries to the nearest $1000.

SELECT name,ROUND(GDP/population,-3) FROM world
WHERE GDP >=1000000000000;

11、Name and capital have the same length

显示字符长度是一样的国家名称和首都名称,你可以使用LENGTH函数来判定字符串长度。

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.

You can use the LENGTH function to find the number of characters in a string

SELECT name,capital FROM world
WHERE LENGTH(name)=LENGTH(capital);

12、Matching name and capital

显示开头字母相同的国家名称、首都名称,但是国家名称和首都名称不能相同。

你可以使用LEFT函数来锁定首字母,可以用不等于号(<>)来进行不等于判定。

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.
  • You can use the function LEFT to isolate the first character.
  • You can use <> as the NOT EQUALS operator.
SELECT name,capital FROM world
WHERE LEFT(name)=LEFT(capital) AND name<>capital;

13、All the vowels(有难度,☆☆☆☆)

显示包含所有元音字母(aeiou),而且不能有空格的国家名称。

赤道几内亚和多米尼加共和国名称中都包含了元音字母(aeiou),但是因为超过一个单词不能被计算在内。

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.

  • You can use the phrase name NOT LIKE '%a%' to exclude characters from your results.
  • The query shown misses countries like Bahamas and Belarus because they contain at least one 'a'
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 '% %';

SQLZOO练习(一)SELECT BASICS,SELECT form world的更多相关文章

  1. SELECT within SELECT Tutorial -- SQLZOO

    SELECT within SELECT Tutorial 注意:where语句中对表示条件的需要用单引号, 下面的译文使用的是有道翻译如有不正确,请直接投诉有道 01.List each count ...

  2. SQL笔记1:SELECT及SELECT高级应用

      T-SQL笔记1:SELECT及SELECT高级应用 本章摘要 1:安装AdventureWorks 2:基本运算符和表达式 3:between 4:like 5:escape 6:TOP 7:G ...

  3. PHP MySQL Select 之Select

    从数据库表中选取数据 SELECT 语句用于从数据库中选取数据. 语法 SELECT column_name(s) FROM table_name 注释:SQL 语句对大小写不敏感.SELECT 与 ...

  4. select * from (select P.*,ROWNUM RN FROM(select * from Mp_Relatedart where pubbaseid=785 order by ID ASC )P)M WHERE M.RN>2 and M.RN <= 7

    select * from (select P.*,ROWNUM RN FROM(select * from Mp_Relatedart where pubbaseid=785 order by ID ...

  5. sql: sybase与oracle中insert into select和select into的用法

    1. sybase与oracle中insert into select和select into的用法 http://wjlvivid.iteye.com/blog/1921679 Sybase 一.首 ...

  6. 关于Select * 与Select 字段名 的问题!

    [转]http://blog.csdn.net/tongyu2009/article/details/8252418 1.SELECT * 语句取出表中的所有字段,不论该字段的数据对调用的应用程序是否 ...

  7. select * 和 select 所有字段的区别

    阅读本文大概需要 1 分钟. 之前发过的文章中,关于 select * 和 select 所有字段的知识,有描述不恰当,这次重新纠正下,加深下理解. MySQL 5.1.37 表记录数 41,547, ...

  8. Insert Into select 与 Select Into 哪个更快?

    在平常数据库操作的时候,我们有时候会遇到表之间数据复制的情况,可能会用到INSERT INTO SELECT 或者 SELECT INTO : 那么二者语法上有什么区别?性能上又如何呢? 围绕着这两个 ...

  9. Linq中的Select与Select many

    Select与Select Many 之前在项目中查询数据库中的数据,都是通过sql语句来查询的,但是随着时代的发展,微软在.Net Framework 4.5版中推出的一个主要的特性——LINQ. ...

随机推荐

  1. 攻防世界-MISC:stegano

    这是攻防世界新手练习区的第五题,题目如下: 点击附件1下载,得到一个pdf文件,打开后内容如下: 把pdf文件里的内容复制到记事本上,发现一串A和B的字符串,不知道是什么(真让人头大) 参考一下WP, ...

  2. XCTF练习题---MISC---Banmabanma

    XCTF练习题---MISC---Banmabanma flag:flag{TENSHINE} 解题步骤: 1.观察题目,打开附件 2.发现是一张斑马图片,这是典型的条形码啊,直接开网站识别 网站:h ...

  3. 【ACM程序设计】并查集

    并查集 并查集(Union-find Sets)是一种非常精巧而实用的数据结构,它主要用于处理一些不相交集合的合并问题.一些常见的用途有:求连通子图.求最小生成树的Kruskal算法和求最近公共祖先( ...

  4. MySQL8新增降序索引

    MySQL8新增降序索引 桃花坞里桃花庵,桃花庵里桃花仙.桃花仙人种桃树,又摘桃花卖酒钱. 一.MySQL5.7 降序索引 MySQL在语法上很早就已经支持降序索引,但实际上创建的却仍然是升序索引,如 ...

  5. python操作MySQL,SQL注入的问题,SQL语句补充,视图触发器存储过程,事务,流程控制,函数

    python操作MySQL 使用过程: 引用API模块 获取与数据库的连接 执行sql语句与存储过程 关闭数据库连接 由于能操作MySQL的模块是第三方模块,我们需要pip安装. pip3 insta ...

  6. CTF简介

    最近在学习渗透测试,后来发现CTF很有趣,发现对学习有所帮助,于是找了几个网站,下面推荐几个我觉得不错的网站 https://www.ctfhub.com/#/index https://adworl ...

  7. Centos 7以上安装Docker (亲测有效)

    一.安装前的准备 我的环境是VMware15虚拟机安装的Centos7,Linux内核是3.10.0-1062.4.1.e17.x86_64 1. 用root账户登录查看操作系统内核版本及相关信息 [ ...

  8. .NET混合开发解决方案16 管理WebView2的用户数据

    系列目录     [已更新最新开发文章,点击查看详细] WebView2控件应用详解系列博客 .NET桌面程序集成Web网页开发的十种解决方案 .NET混合开发解决方案1 WebView2简介 .NE ...

  9. mapstruct 的 mapstruct-processor 自动生成的 Impl 文件中未设置属性值(时好时坏)

    配置依赖和注解处理器 ... <properties> <org.mapstruct.version>1.4.2.Final</org.mapstruct.version ...

  10. docker引起服务器磁盘爆满

    服务器异常 又是开开心心打开我心爱的服务器一天: 吔!这是嘛啊?我的服务器域名访问不了了,一直转圈圈超时了,好,打开ssh远程看看,吔!!!还是访问不了,宕机了?怀着一颗憋大便的心情打开了阿里云控制面 ...