-
Notifications
You must be signed in to change notification settings - Fork 0
/
part-1-global-situation.sql
57 lines (54 loc) · 1.69 KB
/
part-1-global-situation.sql
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
56
57
-- 1.a What was the total forest area (in sq km) of the world in 1990?
-- 41282694.90
SELECT round(forest_area_sqkm::numeric, 2) AS forest_area_sqkm
FROM forestation
WHERE code = 'WLD' AND year = 1990;
-- 1.b - What was the total forest area (in sq km) of the world in 2016?
-- 39958245.90
SELECT round(forest_area_sqkm::numeric, 2) AS forest_area_sqkm
FROM forestation
WHERE code = 'WLD' AND year = 2016;
-- 1.c - What was the change (in sq km) in the forest area of the world from 1990 to 2016?
-- 1324449.00
WITH t1 AS (
SELECT code,
round(forest_area_sqkm::numeric, 2) AS wld_forest_area_1990
FROM forestation
WHERE code = 'WLD' AND year = 1990
),
t2 AS (
SELECT code,
round(forest_area_sqkm::numeric, 2) AS wld_forest_area_2016
FROM forestation
WHERE code = 'WLD' AND year = 2016
)
SELECT wld_forest_area_1990,
wld_forest_area_2016,
abs(wld_forest_area_1990 - wld_forest_area_2016) AS diff_1990_2016
FROM t1
JOIN t2 ON t1.code = t2.code;
-- 1.d - What was the percent change in forest area of the world between 1990 and 2016?
-- 3.21%
WITH t1 AS (
SELECT code,
round(forest_area_sqkm::numeric, 2) AS wld_forest_area_1990
FROM forestation
WHERE code = 'WLD' AND year = 1990
),
t2 AS (
SELECT code,
round(forest_area_sqkm::numeric, 2) AS wld_forest_area_2016
FROM forestation
WHERE code = 'WLD' AND year = 2016
)
SELECT wld_forest_area_1990,
wld_forest_area_2016,
abs(wld_forest_area_1990 - wld_forest_area_2016) AS change,
round(
(
(abs(wld_forest_area_1990 - wld_forest_area_2016) / wld_forest_area_1990) * 100
)::numeric,
2
) AS pct_change
FROM t1
JOIN t2 ON t1.code = t2.code;