Practice · Agriculture · Hard

Cumulative wheat (running total)

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.

What you are given

SUM(million_tonnes) OVER (ORDER BY year) accumulates as the window slides forward. Filter WHERE crop = ‘Wheat’.

Starting point

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.

Did you know

A running total is just SUM() with an ORDER BY inside the window — no self-join required. (SQLite docs)

More Agriculture challenges

Open it in the playground →