-
Notifications
You must be signed in to change notification settings - Fork 0
/
country_summary_info.sql
65 lines (60 loc) · 2 KB
/
country_summary_info.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
58
59
60
61
62
63
64
65
-- short_name, country_code for income group aggregates:
-- 'High income' -- 'HIC'
-- 'Low income' -- 'LIC'
-- 'Lower middle income' -- 'LMC'
-- 'Middle income' -- 'MIC'
-- 'Upper middle income' -- UMC
-- 'Low & middle income' -- 'LMY'
-- Explore country_summary table
SELECT
income_group,
COUNT(income_group)
FROM bigquery-public-data.world_bank_intl_education.country_summary
WHERE region IN ('Latin America & Caribbean')
GROUP BY income_group;
-- Generate a list of countries by income_group, region
SELECT
income_group,
country_code,
short_name,
region
FROM bigquery-public-data.world_bank_intl_education.country_summary
WHERE region IS NOT NULL
ORDER BY income_group, country_code;
-- Count number of countries in each income group
SELECT
income_group,
COUNT(country_code) AS country_count
FROM bigquery-public-data.world_bank_intl_education.country_summary
WHERE income_group IS NOT NULL
GROUP BY income_group;
-- Count the number of countries in each income group per region
SELECT
income_group,
region,
COUNT(country_code) AS country_count
FROM bigquery-public-data.world_bank_intl_education.country_summary
WHERE income_group IS NOT NULL
GROUP BY income_group, region
ORDER BY income_group, country_count DESC;
-- Count the number of countries in each income group per region
-- Improve ordering by creating new income_group ranks
SELECT
CASE
WHEN income_group IN ('High income: OECD')
THEN '1 High income: OECD'
WHEN income_group IN ('High income: nonOECD')
THEN '2 High income: nonOECD'
WHEN income_group IN ('Upper middle income')
THEN '3 Upper middle income'
WHEN income_group IN ('Lower middle income')
THEN '4 Lower middle income'
WHEN income_group IN ('Low income')
THEN '5 Low income'
ELSE 'undefined' END AS income_rank,
region,
COUNT(country_code) AS country_count
FROM bigquery-public-data.world_bank_intl_education.country_summary
WHERE income_group IS NOT NULL
GROUP BY income_rank, region
ORDER BY income_rank, country_count DESC;