-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlzoo_solution
55 lines (47 loc) · 1.26 KB
/
sqlzoo_solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
SQLZOO solution (edition 2020)
*/
/*
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.
/*
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' and 'Denmark')
--3.
/*
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
--4.
--5.
/*
Show each country that begins with G
*/
SELECT name
FROM world
WHERE name LIKE 'G%'
--6.
/*
Show the area in 1000 square km. Show area/1000 instead of area
*/
SELECT name, area/1000
FROM world
WHERE area BETWEEN 200000 AND 250000