-
Notifications
You must be signed in to change notification settings - Fork 0
/
international_debt_analysis
52 lines (44 loc) · 1.57 KB
/
international_debt_analysis
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
#Inspect the international debt data.
SELECT *
FROM international_debt
LIMIT 10;
#Find the number of distinct countries.
SELECT COUNT(DISTINCT country_name) AS total_distinct_countries
FROM international_debt;
#Extract the unique debt indicators in the table.
SELECT DISTINCT indicator_code AS distinct_debt_indicators
FROM international_debt
ORDER BY distinct_debt_indicators;
#Find out the total amount of debt.
SELECT ROUND(SUM(debt) / 1000000, 2) AS total_debt
FROM international_debt;
#Find out the country owing to the highest debt.
SELECT country_name, SUM(debt) AS total_debt
FROM international_debt
GROUP BY country_name
ORDER BY total_debt DESC
LIMIT 1;
#Determine the average amount of debt owed across the categories.
SELECT indicator_code AS debt_indicator, indicator_name, AVG(debt) AS average_debt
FROM international_debt
GROUP BY debt_indicator, indicator_name
ORDER BY average_debt DESC
LIMIT 10;
#Find out the country with the highest amount of principal repayments.
SELECT country_name, indicator_name
FROM international_debt
WHERE debt = (SELECT MAX(debt)
FROM international_debt
WHERE indicator_code = 'DT.AMT.DLXF.CD');
#Find out the debt indicator that appears most frequently.
SELECT indicator_code, COUNT(indicator_code) AS indicator_count
FROM international_debt
GROUP BY indicator_code
ORDER BY indicator_count DESC, indicator_code DESC
LIMIT 20;
#Get the maximum amount of debt that each country owes.
SELECT country_name, MAX(debt) AS maximum_debt
FROM international_debt
GROUP BY country_name
ORDER BY maximum_debt DESC
LIMIT 10;