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.
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.
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;