Practice · History · Hard

The gaps between discoveries

Return name, discovery_year and years_since_previous — the gap to the previous discovery in chronological order — earliest first. The first row has no previous find.

Runs in your browser. No signup needed.

What you are given

discoveries(name, discovery_year). Use LAG() to reach the previous row.

Starting point

SELECT name, discovery_year,
       discovery_year - LAG(discovery_year) OVER (ORDER BY ...) AS years_since_previous
FROM discoveries
ORDER BY ...;

The reference solution is checked automatically when you run your query on the practice page — results are compared row by row, and order matters for this one.

Did you know

LAG returns NULL for the first row because there is nothing behind it — a reminder that window functions still respect the edges of the data.

More History challenges

Open it in the playground →