BaşlayınÜcretsiz başlayın

Running totals of athlete medals

The running total (or cumulative sum) of a column helps you determine what each row's contribution is to the total sum.

Bu egzersiz, kursun bir parçasıdır

PostgreSQL Summary Stats and Window Functions

Kursa Göz Atın

Egzersiz talimatları

  • Return the athletes, the number of medals they earned, and the medals running total, ordered by the athletes' names in alphabetical order.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

WITH Athlete_Medals AS (
  SELECT
    Athlete, COUNT(*) AS Medals
  FROM Summer_Medals
  WHERE
    Country = 'USA' AND Medal = 'Gold'
    AND Year >= 2000
  GROUP BY Athlete)

SELECT
  -- Calculate the running total of athlete medals
  ___,
  ___,
  ___ OVER (ORDER BY ___ ASC) AS Max_Medals
FROM Athlete_Medals
ORDER BY Athlete ASC;
Kodu Düzenle ve Çalıştır