Aggregating and sorting populations
You are interested in planning your next vacation. You think it would be fun to visit a country that has changed a lot in recent years. You figure one way to look at change is to look at a change in population. So you focus on countries with big changes in population over the past 25 years.
You have annual population data from the World Bank covering each year from 1990 to 2017. Find the countries with the biggest population changes. Check your query plan to see how the aggregations impact the plan.
This exercise is part of the course
Improving Query Performance in PostgreSQL
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
SELECT country
, region
, MAX(population) - MIN(population) as population_change
FROM country_pop
GROUP BY ___, ___;