开始进行SQL
的练习,选择了sqlzoo网站
表结构
image练习题
主要是练习where
语句的使用
-- 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
- 产生下表的结果
image
select name, population
from world
wher populantion between 1000000 and 1250000
- 通配符使用
select name, population
from world
where name like "AL%" -- AL开头的名字
image
- Select the code which shows the countries that end in A or L
select name
from world
where name like "a%" or name like "%l"
- 代码运行结果
select name, length(name)
from world
where length(name)=5 and region="Europe"
image
- 代码运行结果
select name, area*2
from world
where population = 64000
image
- Select the code that would show the countries with an area larger than 50000 and a population smaller than 10000000
select name, area, population
from world
where area > 50000 and population < 1000000;
- Select the code that shows the population density of China, Australia, Nigeria and France
笔记:题目中要求的是人口密度
select name, population / area
from world
where name in ('China', 'Nigeria', 'France', 'Australia')
网友评论