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
Yipee!!! this does the trick:
SELECT f.id, f.length, (f.length - ISNULL(f2.length,0)) AS diff FROM foo f LEFT OUTER JOIN foo f2 ON f2.id = (f.id +1)
Please check for other cases also, it is working for the values you posted! Note this is for SQL Server 2005