This is something that is easy to do in a spreadsheet, but not in a database. Fortunately, thanks to Window Functions, it's also not hard in a database - it just requires a bit of setup.

Why? There is no inherent order to records in a database. You "see" them in order of course, when you look at a table or view, but the order you see is applied "on the fly" by some kind of order by command or internal sort (such as a primary key). The actual order of records is quite random and can change if records are updated or when new records are added. So when working with time series, to calculate things that change over time requires using the LEAD and LAG Window Functions. These functions takes input about the ordering of records and then look backward or forward over the records in that order to calculate changes between those records.

Here is the LAG function in use. This example calculates the pumping indicated by the change in a well's meter reading from one month to the next. The OVER parameters keep different wells distinct with the PARTITION BY clause and sorts the records with the ORDER BY clause.

SELECT well_ndx, year, month, meter_reading,
       meter_reading - LAG(meter_reading) 
			 OVER (PARTITION BY well_ndx ORDER BY by year, month) as pumping,
from well_meter_readings;

NOTE: Both the LAG and LEAD functions also have an "offset" parameter, which is an integer indicating how many records to look back or forward. The offset defaults to 1, and for the LAG this means it will look backward 1 record and for the LEAD function it will look forward 1 record. You can use negatives for the offset, effectively making either function look backward or forward!