This project was completed as a practice exercise through DataCamp's virtual environment. Using the international_debt
table, Queries include COUNT(DISTINCT)
, SUM( )
, and ORDER BY
to analyze debt by country.
The dataset was sourced from DataCamp and reflects the debt profile of developing countries. Each entry includes the country name, debt indicator, and monetary value in current USD.
The goal was to explore:
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.
international_debt
Column | Description | Type |
---|---|---|
country_name | Name of the country | VARCHAR |
country_code | Code representing the country | VARCHAR |
indicator_name | Debt indicator description | VARCHAR |
indicator_code | Debt indicator code | VARCHAR |
debt | Value of the debt indicator (USD) | FLOAT |
-- Number of distinct countries
SELECT COUNT(DISTINCT country_name) AS total_distinct_countries
FROM international_debt;
This SQL query calculates the number of unique countries present in the international_debt
table. It uses COUNT(DISTINCT country_name)
to count the distinct values in the country_name
column, giving a single result representing the total number of countries listed in the dataset.
-- Country with 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;
This query identifies the country with the highest total debt in the international_debt
dataset. It groups the data by country_name
and calculates the total debt using SUM(debt)
. The results are sorted in descending order by total debt and limited to the top row using LIMIT 1
, returning the single country with the highest total debt.
-- Country with the lowest repayments
SELECT country_name, indicator_name, MIN(debt) AS lowest_repayment
FROM international_debt
WHERE indicator_code = 'DT.AMT.DLXF.CD'
GROUP BY country_name, indicator_name
ORDER BY lowest_repayment ASC
LIMIT 1;
This query finds the country with the lowest principal repayments based on the debt indicator DT.AMT.DLXF.CD
. It filters the dataset using WHERE indicator_code = 'DT.AMT.DLXF.CD'
, then groups by country_name
and indicator_name
. The query returns the minimum repayment value using MIN(debt)
and limits the result to one row showing the lowest repayment.
Thanks to DataCamp for providing the dataset and learning environment for this SQL project.