Get startedGet started for free

Top, middle, and bottom thirds

Splitting your data into thirds or quartiles is often useful to understand how the values in your dataset are spread. Getting summary statistics (averages, sums, standard deviations, etc.) of the top, middle, and bottom thirds can help you determine what distribution your values follow.

This exercise is part of the course

PostgreSQL Summary Stats and Window Functions

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

WITH Athlete_Medals AS (
  SELECT Athlete, COUNT(*) AS Medals
  FROM Summer_Medals
  GROUP BY Athlete
  HAVING COUNT(*) > 1)
  
SELECT
  Athlete,
  Medals,
  -- Split athletes into thirds by their earned medals
  ___ ___ ___ AS Third
FROM Athlete_Medals
ORDER BY Medals DESC, Athlete ASC;
Edit and Run Code