Quantcast
Channel: Question and Answer » oracle
Viewing all articles
Browse latest Browse all 717

Oracle MODEL clause: Carry yesterday's leftovers to today

$
0
0

I’m new to the MODEL clause. I’m trying to track volume of worked/unworked to-do items over time.

What I HAVE is:

work_date 
born   (# of new to-dos per date), 
robo   (# of computer-closed to-dos per date) 
worked (# of human-close to-dos per date). 

What I want to GENERATE is additional columns for:

carryover (# of leftovers from yesterday)
workable  (carryover + born - robo)
leftover  (today's workable - worked)

I got half of what I want with:

select work_date, carryover, born, robo, workable, worked, leftover
from ( ... )   
model
ignore nav
dimension by (work_date)
measures ( 0 as carryover, born, robo, 0 as workable, worked, 0 as leftover )
rules 
        (
           carryover[work_date]  = leftover[cv(work_date)-1],
           workable[work_date]   = carryover[cv(work_date)] +   born[cv(work_date)] - robo[cv(work_date)],
           leftover[work_date]   = workable[cv(work_date)] -    worked[cv(work_date)]
    )
order by work_date

but carryover is always 0, for reasons not clear to me. (OK, I threw in an ITERATE (100) just for the sake of experimentation and some good old cargo cult programming, and did get the right results, but why, and how to choose a correct iterate size is even LESS clear to me)

http://sqlfiddle.com/#!4/47271/1


Viewing all articles
Browse latest Browse all 717

Trending Articles