You can do this with LEAD
provided the version you are on supports it.
select customer,orderdate,item,
lead(orderdate,1) over(partition by customer order by date) as second_date,
lead(item,1) over(partition by customer order by date) as second_item,
lead(orderdate,2) over(partition by customer order by date) as third_date,
lead(item,2) over(partition by customer order by date) as third_item
from tbl
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments