Get startedGet started for free

All group-level subtotals

You want to break down all medals awarded to Russia in the 2012 Olympic games per gender and medal type. Since the medals all belong to one country, Russia, it makes sense to generate all possible subtotals (Gender- and Medal-level subtotals), as well as a grand total.

Generate a breakdown of the medals awarded to Russia per country and medal type, including all group-level subtotals and a grand total.

This exercise is part of the course

PostgreSQL Summary Stats and Window Functions

View Course

Exercise instructions

  • Count the medals awarded per gender and medal type.
  • Generate all possible group-level counts (per gender and medal type subtotals and the grand total).

Hands-on interactive exercise

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

-- Count the medals per gender and medal type
SELECT
  ___,
  ___,
  ___ AS Awards
FROM Summer_Medals
WHERE
  Year = 2012
  AND Country = 'RUS'
-- Get all possible group-level subtotals
GROUP BY ___
ORDER BY Gender ASC, Medal ASC;
Edit and Run Code