How can I add another column where will be the difference between 2nd and 3rd row, than the 3rd and the 4th and so on. Thanks in advance!
Asked
Active
Viewed 39 times
1 Answers
2
Use lag()
:
select d.*,
(department_id - lag(department_id) over (order by department_id)) as diff
from departments d;

Gordon Linoff
- 1,242,037
- 58
- 646
- 786