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
  • 42,561
  • 8
  • 45
  • 63
Savke
  • 131
  • 3
  • 11

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,242,037
  • 58
  • 646
  • 786