Skip to content

Humans not only take debts to manage 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 project, you 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. You are going to find the answers to the following questions:

  • What is the number of distinct countries present in the database?
  • What country has the highest amount of debt?
  • What country has the lowest amount of repayments?

Below is a description of the table you will be working with:

international_debt table

ColumnDefinitionData Type
country_nameName of the countryvarchar
country_codeCode representing the countryvarchar
indicator_nameDescription of the debt indicatorvarchar
indicator_codeCode representing the debt indicatorvarchar
debtValue of the debt indicator for the given country (in current US dollars)float

You will execute SQL queries to answer three questions, as listed in the instructions.

Spinner
DataFrameas
df1
variable
SELECT * 
FROM public.international_debt
LIMIT 10;
Spinner
DataFrameas
df
variable
---What is the total debt across all countries? 

SELECT SUM(debt) as total_debt
FROM international_debt
Spinner
DataFrameas
df2
variable
--- What are the top 5 countries with the most debt?

SELECT country_name,SUM(debt) as total_debt
FROM international_debt 
GROUP BY country_name
ORDER BY total_debt DESC
LIMIT 5;
Spinner
DataFrameas
df3
variable
--- What is the total debt,average debt for a South Africa

SELECT country_name, ROUND(SUM(debt),3) AS total_debt_southafrica , ROUND(AVG(debt),3) AS avg_debt_southafrica
FROM international_debt
WHERE country_name = 'South Africa'
GROUP BY country_name
LIMIT 1;
Spinner
DataFrameas
df4
variable
--- How many debt indicators are recorded in the dataset?

SELECT COUNT(DISTINCT indicator_name) AS number_of_indicators
FROM international_debt;
Spinner
DataFrameas
df6
variable
---Which debt indicator has the highest value?

SELECT indicator_name, SUM(debt) AS total_debt
FROM international_debt
GROUP BY indicator_name
ORDER BY total_debt DESC
LIMIT 1;
Spinner
DataFrameas
df5
variable
---What is the average debt per country?

SELECT AVG(total_debt) AS average_debt_per_country
FROM (
    SELECT country_name, SUM(debt) AS total_debt
    FROM international_debt
    GROUP BY country_name
) AS country_debt;
Spinner
DataFrameas
df7
variable
--- Which countries have more than a certain amount of debt (e.g., 1 billion USD)

SELECT country_name, SUM(debt) AS total_debt
FROM international_debt 
GROUP BY country_name
HAVING SUM(debt) > 1000000000
ORDER BY sum(debt) DESC
LIMIT 10;