Deducting Values

Analytics
N/A

Deducting Values

How do I minus one field with the previous one, eg,

VALUE
0 - field value should =0
17 - field value should = 17 (17 - 0)
23 - field value should = 6 (23 - 17)
25 - field value should = 2 (25 - 23)
1 REPLY

Re: Deducting Values


SELECT VAL, VAL - COALESCE(SUM(VAL) OVER(ORDER BY VAL ROWS BETWEEN 1 PRECEDING AND 1 PRECEDING), 0) DIFF
FROM MYTABLE
;

VAL DIFF
0 0
17 17
23 6
25 2