I am trying to figure out the best way to calculate differences between a value and the value in the previous row. I have come up with several possible ways to do this, but I don't have a lot of SQL experience and would be grateful for help from someone who has done this before.
Here is a sample of my data:
ID VALUE
-- -----
1 12
2 15
3 18
4 9
5 13
I would like to find the differences between the value in the current row and the value in the previous row. Something like this:
ID DIFF
-- ----
2 3
3 3
4 -9
5 4
It seems like I need to do some sort of recursive view or subquery and then get the difference between the two aliases of the table, one of which is one row behind the other.
Thanks for any advice!
Nathan Schultz
Here is a sample of my data:
ID VALUE
-- -----
1 12
2 15
3 18
4 9
5 13
I would like to find the differences between the value in the current row and the value in the previous row. Something like this:
ID DIFF
-- ----
2 3
3 3
4 -9
5 4
It seems like I need to do some sort of recursive view or subquery and then get the difference between the two aliases of the table, one of which is one row behind the other.
Thanks for any advice!
Nathan Schultz