Medaglie massime per paese per anno
Ottenere il massimo delle medaglie guadagnate finora da un paese ti aiuta a capire se ha battuto il proprio record confrontando le medaglie dell'anno corrente con il massimo raggiunto finora.
Questo esercizio fa parte del corso
Statistiche riepilogative e funzioni finestra in PostgreSQL
Istruzioni dell'esercizio
- Restituisci l'anno, il paese, le medaglie e il massimo di medaglie guadagnate finora per ciascun paese, ordinate per anno in ordine crescente.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
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;