Practice · Agriculture · Hard
For wheat only, return each year, its million_tonnes, and the running cumulative total up to and including that year as cumulative (2 decimals), oldest first.
Runs in your browser. No signup needed.
SUM(million_tonnes) OVER (ORDER BY year) accumulates as the window slides forward. Filter WHERE crop = ‘Wheat’.
SELECT year, million_tonnes,
ROUND(SUM(million_tonnes) OVER (ORDER BY year), 2) AS cumulative
FROM crops
WHERE crop = 'Wheat'
ORDER BY year;
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.
A running total is just SUM() with an ORDER BY inside the window — no self-join required. (SQLite docs)