MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

PostgreSQL Summary Stats and Window Functions

Lihat Kursus

Petunjuk latihan

  • 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).

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

-- 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 dan Jalankan Kode