各國歷年最高獎牌數
取得一個國家截至目前為止的最高累積獎牌數,有助於你將當年獲得的獎牌數與過往最高值比較,判斷該國是否刷新了獎牌紀錄。
本練習屬於課程
PostgreSQL 統計摘要與視窗函式
練習說明
- 請回傳年份、國家、獎牌數,以及各國截至目前為止的最高累積獎牌數,並依年份遞增排序。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
WITH Country_Medals AS (
SELECT
Year, Country, COUNT(*) AS Medals
FROM Summer_Medals
WHERE
Country IN ('CHN', 'KOR', 'JPN')
AND Medal = 'Gold' AND Year >= 2000
GROUP BY Year, Country)
SELECT
-- Return the max medals earned so far per country
___,
___,
___,
___ OVER (PARTITION BY ___
ORDER BY ___ ASC) AS Max_Medals
FROM Country_Medals
ORDER BY Country ASC, Year ASC;