If I have
id minutes
1 2:40:00
1 3:40:00
1 5:40:00
2 6:40:00
2 7:40:00
2 8:40:00
With the lag function
SELECT id, minutes as earlier_time, lag(minutes) OVER(PARTITION BY id ORDER BY id, minutes) as later_time FROM table1
I get
id earlier_time
1 2:40:00 3:40:00
1 3:40:00 5:40:00
1 5:40:00 NULL
2 6:40:00 7:40:00
2 7:40:00 8:40:00
2 8:40:00 NULL
Is there a way to do that without the lag function?