sql - How can I select the difference between two rows? -


here's example of i'm looking for:

i have data comes in lifetime total in gallons. want able display data running total on time period selecting rather lifetime total. example:

timestamp   lifetimetotal        runningtotal 1:30            3000                 0 1:31            3001                 1 1:32            3005                 5 1:33            3010                 10 

i'm not sure how go doing this. looking @ examples this one using over it's not quite i'm looking for: don't want add rows every time, rather want add difference between 2 rows. right selecting lifetime totals , displaying that.

any ideas? add code if necessary there's not show besides select statement; having trouble thinking of way conceptually.

this should give difference between current lifetimetotal , min lifetimetotal

select timestamp,         lifetimetotal,        lifetimetotal - min(lifetimetotal) on () runningtotal   table 

Comments