In PostgreSQL the lag()
function returns the value from a previous row, specified by the given offset.
The offset specifies how many rows prior to the current row to get the value from. For example, an offset of 1
gets the value from the previous row.