The below sample data has a cumulative size for each entry. I am trying to write a query to update the size, with the difference in size with the previous timestamp(For example – row 2 should be updated with (4478.74 – 4476) = 2.74) for the same item name. Please help me on this one.
Row Item Size Time
-----------------------------------------------
1 ItemA 4476 7/01/2012 11:15
2 ItemA 4478.74 7/01/2012 11:20
3 ItemA 4478.82 7/01/2012 11:21
4 ItemA 4487.51 7/01/2012 11:29
5 ItemB 1.53 7/01/2012 11:29
6 ItemB 1.67 7/01/2012 11:20
7 ItemB 1.84 7/01/2012 11:21
8 ItemB 2.18 7/01/2012 11:15
You can partition the data by Item and then outer join it to itself on the previous row number:
Resulting Output: