I would like to create a query to calculate the difference (in meters) between the current value and the last value recorded.
Follow my SpareParts
table:
----------------------------
|Serial | PartCode | Meter |
----------------------------
| 1 | A | 1000 |
| 1 | A | 2000 |
| 1 | A | 2500 |
| 1 | A | 4000 |
| 2 | A | 1000 |
| 2 | A | 1400 |
| 2 | A | 2900 |
| 1 | B | 5000 |
| 1 | B | 9000 |
| 1 | B | 14000 |
----------------------------
And I would like a result like this :
-----------------------------------
|Serial | PartCode | Meter | Diff |
-----------------------------------
| 1 | A | 1000 | 0 |
| 1 | A | 2000 | 1000 |
| 1 | A | 2500 | 500 |
| 1 | A | 4000 | 1500 |
| 2 | A | 1000 | 0 |
| 2 | A | 1400 | 400 |
| 2 | A | 2900 | 1500 |
| 1 | B | 5000 | 0 |
| 1 | B | 9000 | 4000 |
| 1 | B | 14000 | 5000 |
-----------------------------------
Diff = Current Meter - Last Meter
Could you help me with this question?
Thanks,