0

enter image description here

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!

jarlh
  • 40,041
  • 8
  • 39
  • 58
Savke
  • 131
  • 1
  • 10

1 Answers1

2

Use lag():

select d.*,
       (department_id - lag(department_id) over (order by department_id)) as diff
from departments d;
Gordon Linoff
  • 1,198,228
  • 53
  • 572
  • 709