Windows I — ranking & offsets
Exercise · SQL & Querying

Predict, then run it

Predict the output

oil(night, litres) = (1,100),(2,90),(3,75). Litres used per night; night one has no previous reading, so default the baseline to that night's own level (zero used):

SELECT night, litres - LAG(litres, 1, litres) OVER (ORDER BY night) AS used FROM oil ORDER BY night;

Predict the exact output.