Fork me on GitHub

sqlzoo练习1

开始进行SQL的练习,选择了sqlzoo网站

表结构

练习题

主要是练习where语句的使用

1
2
3
4
5
6
7
8
9
10
11
-- 1
SELECT population FROM world
WHERE name = 'Germany'

-- 2
SELECT name, population FROM world
WHERE name IN ('Sweden', 'Norway','Denmark');

-- 3
SELECT name, area FROM world
WHERE area BETWEEN 200000 AND 250000

quiz

  1. 产生下表的结果

1
2
3
select name, population
from world
wher populantion between 1000000 and 1250000
  1. 通配符使用
1
2
3
select name, population
from world
where name like "AL%" -- AL开头的名字

  1. Select the code which shows the countries that end in A or L
1
2
3
select name
from world
where name like "a%" or name like "%l"
  1. 代码运行结果
1
2
3
select name, length(name)
from world
where length(name)=5 and region="Europe"

  1. 代码运行结果
1
2
3
select name, area*2
from world
where population = 64000

  1. Select the code that would show the countries with an area larger than 50000 and a population smaller than 10000000
1
2
3
select name, area, population
from world
where area > 50000 and population < 1000000;
  1. Select the code that shows the population density of China, Australia, Nigeria and France

笔记:题目中要求的是人口密度

1
2
3
select name, population / area
from world
where name in ('China', 'Nigeria', 'France', 'Australia')

本文标题:sqlzoo练习1

发布时间:2020年01月13日 - 11:01

原始链接:http://www.renpeter.cn/2020/01/13/sqlzoo%E7%BB%83%E4%B9%A01.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

Coffee or Tea