Reputation: 167
How would I join a table onto itself and offset the second table to shift up by 1 row?
I want to do this in order to calculate the amount of days until the next sale date.
Upvotes: 1
Views: 424
Reputation: 1269873
If you have data recording sales, then you would get the next date using lead()
:
select s.*,
lead(saledate) over (partition by customerid order by saledate) as next_saledate
from sales s;
Upvotes: 2