http://phecoopwm6x7azx26ctuqcp6673bbqkrqfeoiz2wwk36sady5tqbdpqd.onion/posts/sql/calculating-the-difference-between-subsequent-values-in-sql.html
This might be necessary, for example, if a record's value is drawn from a cumulative total (such as packet counter on a switch) - we're not really interested in the total value so much as the change over time. The LAG function can be used to look at the previous value, whilst LEAD can be used to look at the next If the source is something like a packet counter, it might also be desirable to generate a...