Where are all the athletes from
The Olympics occurs every two years (Summer & Winter) and is an event that people worldwide watch. It sparks national pride as people root for athletes representing their own country. In this exercise, you will be looking at recent Olympic athletes data (2014 and 2016) to find which countries participated. You will need to join it to regional information that lists all countries who have ever participated in prior Olympics.
Here, you will join together the athletes
and oregions
tables to return countries with participating athletes.
Feel free to explore the data to see if you recognize any of the athletes from your own country.
This exercise is part of the course
Improving Query Performance in PostgreSQL
Exercise instructions
- Join
athletes
tooregions
using the country code. - Alias each table. Use
ath
forathletes
andreg
fororegions
. - Check if you have any countries with no athletes.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
-- Athlete count by country and region
SELECT reg.region
, reg.country
, COUNT(DISTINCT ath.athlete_id) AS no_athletes -- Athletes can compete in multiple events
FROM ___ ___
___ ___ ___ ___
ON reg.olympic_cc = ath.country_code
GROUP BY reg.region, reg.country
ORDER BY no_athletes;