IniziaInizia gratis

Last country by name

Just like you can get the first row's value in a dataset, you can get the last row's value. This is often useful when you want to compare the most recent value to previous values.

Questo esercizio fa parte del corso

PostgreSQL Summary Stats and Window Functions

Visualizza il corso

Istruzioni dell'esercizio

  • Return the year and the city in which each Olympic games were held.
  • Fetch the last city in which the Olympic games were held.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

WITH Hosts AS (
  SELECT DISTINCT Year, City
    FROM Summer_Medals)

SELECT
  Year,
  City,
  -- Get the last city in which the Olympic games were held
  ___ OVER (
   ORDER BY ___ ASC
   RANGE BETWEEN
     UNBOUNDED PRECEDING AND
     UNBOUNDED FOLLOWING
  ) AS Last_City
FROM Hosts
ORDER BY Year ASC;
Modifica ed esegui il codice