I'm trying to rank calls through our IVR based on the number of calls that occurred before it in the previous 30 days (ie is this the 1st, 2nd, 3rd .... call in the last 30 days?)
I can do this for a fixed 30 day window, but I need to rank calls wihtin a rolling 30 day window over a long period of time. I've tried using the RANK () OVER(PARTITION .... approach, however it will not accept a variable partition.
SELECT
call_ID ,
end_dt,
end_tm,
CUST_TN,
RANK() OVER (PARTITION BY BTN, [Rolling 30 day partition here] ORDER BY end_dt, end_tm ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW ) Prev_Rec
FROM ivr.vivr_calls
WHERE end_dt BETWEEN '2012-09-01' AND '2012-10-31'
QUALIFY end_dt BETWEEN '2012-10-01' AND '2012-10-31'
Any ideas?
Thanks - Steve
↧