Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT h.salesorderheaderid, h.customerid, h.orderdate
- , TRUNC(MAX(h.orderdate) over (PARTITION BY h.customerid) - h.orderdate) AS days_to_lastorder1
- , TRUNC(FIRST_VALUE(h.orderdate) over (PARTITION BY h.customerid ORDER BY h.orderdate DESC) - h.orderdate) AS days_to_lastorder2
- FROM dbmaster.salesorderheader h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement