Future gold medalists
Fetching functions allow you to get values from different parts of the table into one row. If you have time-ordered data, you can "peek into the future" with the LEAD fetching function. This is especially useful if you want to compare a current value to a future value.
Questo esercizio fa parte del corso
PostgreSQL Summary Stats and Window Functions
Istruzioni dell'esercizio
- For each year, fetch the current gold medalist and the gold medalist 3 competitions ahead of the current row.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
WITH Discus_Medalists AS (
SELECT DISTINCT
Year,
Athlete
FROM Summer_Medals
WHERE Medal = 'Gold'
AND Event = 'Discus Throw'
AND Gender = 'Women'
AND Year >= 2000)
SELECT
-- For each year, fetch the current and future medalists
___,
___,
___ OVER (ORDER BY ___ ASC) AS Future_Champion
FROM Discus_Medalists
ORDER BY Year ASC;