Get startedGet started for free

Summarizing results

After ranking each country in the 2000 Olympics by gold medals awarded, you want to return the top 3 countries in one row, as a comma-separated string. In other words, turn this:

| Country | Rank |
|---------|------|
| USA     | 1    |
| RUS     | 2    |
| AUS     | 3    |
| ...     | ...  |

into this:

USA, RUS, AUS

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 Country_Medals AS (
  SELECT
    Country,
    COUNT(*) AS Medals
  FROM Summer_Medals
  WHERE Year = 2000
    AND Medal = 'Gold'
  GROUP BY Country)

  SELECT
    Country,
    -- Rank countries by the medals awarded
    ___ AS Rank
  FROM Country_Medals
  ORDER BY Rank ASC;
Edit and Run Code