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

Moving average of Russian medals

Using frames with aggregate window functions allow you to calculate many common metrics, including moving averages and totals. These metrics track the change in performance over time.

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

PostgreSQL Summary Stats and Window Functions

Kursa Göz Atın

Egzersiz talimatları

  • Calculate the 3-year moving average of medals earned.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

WITH Russian_Medals AS (
  SELECT
    Year, COUNT(*) AS Medals
  FROM Summer_Medals
  WHERE
    Country = 'RUS'
    AND Medal = 'Gold'
    AND Year >= 1980
  GROUP BY Year)

SELECT
  Year, Medals,
  --- Calculate the 3-year moving average of medals earned
  ___ OVER
    (ORDER BY Year ASC
     ROWS BETWEEN
     ___ AND ___) AS Medals_MA
FROM Russian_Medals
ORDER BY Year ASC;
Kodu Düzenle ve Çalıştır