ASiwon Apr 10th, 2020 182 Never
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
RAW Paste Data