Advertisement
ASiwon

DBMaster_ZD_T6_2

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