Sql -International Debt analysis
It's not that we humans only take debts to manage our necessities. A country may also take debt to manage its economy. For example, infrastructure spending is one costly ingredient required for a country's citizens to lead comfortable lives. The World Bank is the organization that provides debt to countries.
In this notebook, we are going to analyze international debt data collected by The World Bank. The dataset contains information about the amount of debt (in USD) owed by developing countries across several categories. We are going to find the answers to questions like:
- What is the total amount of debt that is owed by the countries listed in the dataset?
- Which country owns the maximum amount of debt and what does that amount look like?
- What is the average amount of debt owed by countries across different debt indicators?
Below is a snapshot of the database you will be working with:
| country_name | country_code | indicator_name | indicator_code | debt |
|---|---|---|---|---|
| Afghanistan | AFG | "Disbursements on external debt, long-term (DIS, current US$)" | DT.DIS.DLXF.CD | 72894453.7 |
| Afghanistan | AFG | "Interest payments on external debt, long-term (INT, current US$)" | DT.INT.DLXF.CD | 53239440.1 |
| Afghanistan | AFG | "PPG, bilateral (AMT, current US$)" | DT.AMT.BLAT.CD | 61739336.9 |
| Afghanistan | AFG | "PPG, bilateral (DIS, current US$)" | DT.DIS.BLAT.CD | 49114729.4 |
| Afghanistan | AFG | "PPG, bilateral (INT, current US$)" | DT.INT.BLAT.CD | 39903620.1 |
| Afghanistan | AFG | "PPG, multilateral (AMT, current US$)" | DT.AMT.MLAT.CD | 39107845 |
| Afghanistan | AFG | "PPG, multilateral (DIS, current US$)" | DT.DIS.MLAT.CD | 23779724.3 |
| Afghanistan | AFG | "PPG, multilateral (INT, current US$)" | DT.INT.MLAT.CD | 13335820 |
| Afghanistan | AFG | "PPG, official creditors (AMT, current US$)" | DT.AMT.OFFT.CD | 100847181.9 |
| Afghanistan | AFG | "PPG, official creditors (DIS, current US$)" | DT.DIS.OFFT.CD | 72894453.7 |
You will execute SQL queries to answer six questions, as listed in the instructions.
--num_distinct_countries
-- Task 1
SELECT
COUNT(DISTINCT international_debt.country_name) AS total_distinct_countries
FROM international_debt;
--distinct_debt_indicators
-- Task 2
select distinct(indicator_name) as distinct_debt_indicators
from public.international_debt
order by distinct_debt_indicators;
--total_debt
-- Task 3
select round(sum(debt)/1000000,2) as total_debt
from public.international_debt;
--highest_debt_country
-- Task 4
select country_name as highest_debt_country, sum(debt)
from public.international_debt
group by public.international_debt.country_name
order by sum(debt) desc
LIMIT 1;
--avg_debt_per_indicator
select public.international_debt.indicator_name, public.international_debt.indicator_code, avg(public.international_debt.debt)as avg_debt_per_indicator
from public.international_debt
group by public.international_debt.indicator_name, public.international_debt.indicator_code
order by avg_debt_per_indicator DESC;
--highest_principal_repayment
-- Task 6
select max(public.international_debt.debt) AS highest_principal_repayment
from public.international_debt
group by public.international_debt.indicator_code
HAVING public.international_debt.indicator_code='DT.AMT.DLXF.CD';