Wednesday, August 27, 2014

Claculating difference between the rows...

Assuming yor column names are ColA, ColB, and ColC, then if you are on SQL 2012 or later, you can do



Select ColA, ColB, ColC,
IsNull(ColC - Lag(ColC) Over(Partition By ColA Order By ColB), 0)
From yourtable



Tom

No comments:

Post a Comment