top of page

Exploring Global Life Expectancy with MySQL

Updated: Jul 15

ree







Project Overview

In this SQL-based exploratory data analysis (EDA), we analyze the world_life_expectancy dataset to investigate how health and economic factors relate to life expectancy across countries and years. The analysis focuses on the following core areas:


  • 📈 Change in life expectancy over time: We calculate the increase in life expectancy per country and analyze global trends across years.

  • 💸 Relationship between life expectancy and economic status (GDP): Using average GDP, we explore how wealthier versus poorer countries compare in terms of life expectancy.

  • 🌍 Health inequality between Developed and Developing countries: We compare average life expectancy by country status to assess the global health divide.

  • 🧮 Impact of other health indicators: BMI and adult mortality are analyzed in relation to life expectancy to reveal further health-related patterns.



Life Expectancy Change Over 15 Years (Per Country)


SELECT country,

MIN(`Life expectancy`),

MAX(`Life expectancy`),

ROUND(MAX(`Life expectancy`) - MIN(`Life expectancy`), 1) AS Life_Increase_15_Years

FROM world_life_expectancy

GROUP BY country

HAVING MIN(`Life expectancy`) <> 0

AND MAX(`Life expectancy`) <> 0

ORDER BY Life_Increase_15_Years ASC;



ree

Insight:


This query calculates the overall improvement (or decline) in life expectancy for each country over time. It reveals which countries saw the largest gains or smallest changes in health outcomes




Global Average Life Expectancy by Year



SELECT year,

ROUND(AVG(`Life expectancy`), 2)

FROM world_life_expectancy

WHERE `Life expectancy` <> 0

GROUP BY year

ORDER BY year;



ree





























Insight:


 Displays the trend of global life expectancy over the years. It allows for visualization of steady increases, plateaus, or declines across time.



Average Life Expectancy and GDP per Country


SELECT country,

ROUND(AVG(`Life expectancy`), 1) AS life_exp,

ROUND(AVG(GDP), 1) AS GDP

FROM world_life_expectancy

GROUP BY country

HAVING life_exp > 0 AND GDP > 0

ORDER BY GDP DESC;




ree

















Insight:


Correlates economic wealth (GDP) with life expectancy on a per-country basis. It allows us to examine whether higher GDP consistently leads to better health outcomes.



Comparing High and Low GDP Countries


SELECT

SUM(CASE WHEN GDP >= 1500 THEN 1 ELSE 0 END) AS High_GDP_count,

ROUND(AVG(CASE WHEN GDP >= 1500 THEN `Life expectancy` ELSE NULL END), 1) AS High_GDP_Life_exp,

SUM(CASE WHEN GDP < 1500 THEN 1 ELSE 0 END) AS Low_GDP_count,

ROUND(AVG(CASE WHEN GDP < 1500 THEN `Life expectancy` ELSE NULL END), 1) AS Low_GDP_Life_exp

FROM world_life_expectancy;



ree

Insight:


Groups countries into two economic tiers and compares their average life expectancy. Useful for illustrating global inequality in health tied to income levels.



Life Expectancy by Development Status


SELECT status,

COUNT(DISTINCT country),

ROUND(AVG(`Life expectancy`), 1)

FROM world_life_expectancy

GROUP BY status;



ree

Insight:


Highlights the health gap between Developed and Developing countries, quantifying both their count and average life expectancy.



Correlation Between BMI and Life Expectancy



SELECT country,

ROUND(AVG(`Life expectancy`), 1) AS life_exp,

ROUND(AVG(BMI), 1) AS bmi

FROM world_life_expectancy

GROUP BY country

HAVING life_exp > 0 AND bmi > 0

ORDER BY bmi ASC;


ree

Insight:


Examines whether countries with lower or higher average BMI values also report different life expectancy outcomes.



Rolling Sum of Adult Mortality Over Time


SELECT country,

year,

`Life expectancy`,

`Adult Mortality`,

SUM(`Adult Mortality`) OVER(PARTITION BY country ORDER BY year) AS rolling_total

FROM world_life_expectancy;


ree

Insight:


Tracks the cumulative mortality load over the years per country. This can indicate changes in long-term health trends or healthcare effectiveness

Comments


bottom of page