I\'ve been stumped with some SQL where I\'ve got several rows of data, and I want to subtract a row from the previous row and have it repeat all the way down.
So her
This might help you (somewhat).
select a.id, a.length, coalesce(a.length - (select b.length from foo b where b.id = a.id + 1), a.length) as diff from foo a