Reputation: 1449
I would need some help with below case:
My data contains dates of order arrival in one column.
I want to add second column what would use date from one row below:
Upvotes: 1
Views: 342
Reputation: 1270873
Use lead()
:
select t.dept, t.date as arrival, t.next_arrival
from (select t.*, lead(date) over (partition by dept order by date) as next_arrival
from t
) t
where t.next_arrival is not null;
If you are happy with all rows in the result set and the next_arrival
being NULL
, then you don't need the subquery.
Upvotes: 1