|
|
苏大师邀我也参与一下, 我就大致写了一下, 请大家帮忙看看是否合适, 这个可以直接拿来执行:
with tmp(product,som,RemainingNCustomerEOM,NCustomersSOM) --simulate original after group by
as
(
select 'Bronze',date'2016-01-01',100, 200 from dual union all
select 'Bronze',date'2016-02-01' ,80, 100 from dual union all
select 'Bronze',date'2016-03-01' ,50, 200 from dual union all
select 'Bronze',date'2016-04-01' ,40, 200 from dual union all
select 'Bronze',date'2016-05-01' ,80, 100 from dual union all
select 'Bronze',date'2016-06-01' ,20, 50 from dual union all
select 'Bronze',date'2016-07-01' ,80, 200 from dual union all
select 'Bronze',date'2016-08-01' ,80, 200 from dual union all
select 'Bronze',date'2016-09-01' ,80, 200 from dual union all
select 'Bronze',date'2016-10-01' ,80, 200 from dual union all
select 'Bronze',date'2016-11-01' ,80, 200 from dual union all
select 'Bronze',date'2016-12-01' ,80, 200 from dual union all
select 'Bronze',date'2017-01-01' ,80, 200 from dual union all
select 'Bronze',date'2017-02-01' ,80, 200 from dual union all
select 'Bronze',date'2017-03-01' ,80, 200 from dual union all
select 'Gold', date'2016-01-01' ,80, 200 from dual union all
select 'Gold', date'2016-02-01' ,80, 200 from dual union all
select 'Gold', date'2016-03-01' ,80, 200 from dual union all
select 'Gold', date'2016-04-01' ,80, 200 from dual union all
select 'Gold', date'2016-05-01' ,80, 200 from dual union all
select 'Gold', date'2016-06-01' ,80, 200 from dual union all
select 'Gold', date'2016-07-01' ,80, 200 from dual union all
select 'Gold', date'2016-08-01' ,80, 200 from dual union all
select 'Gold', date'2016-09-01' ,80, 200 from dual union all
select 'Gold', date'2016-10-01' ,80, 200 from dual union all
select 'Gold', date'2016-11-01' ,80, 200 from dual union all
select 'Gold', date'2016-12-01' ,80, 200 from dual union all
select 'Gold', date'2017-01-01' ,80, 200 from dual union all
select 'Gold', date'2017-02-01' ,80, 200 from dual union all
select 'Gold', date'2017-03-01' ,80, 200 from dual union all
select 'Silver',date'2016-01-01' ,80, 200 from dual union all
select 'Silver',date'2016-02-01' ,80, 200 from dual union all
select 'Silver',date'2016-03-01' ,80, 200 from dual union all
select 'Silver',date'2016-04-01' ,80, 200 from dual union all
select 'Silver',date'2016-05-01' ,80, 200 from dual union all
select 'Silver',date'2016-06-01' ,80, 200 from dual union all
select 'Silver',date'2016-07-01' ,80, 200 from dual union all
select 'Silver',date'2016-08-01' ,80, 200 from dual union all
select 'Silver',date'2016-09-01' ,80, 200 from dual union all
select 'Silver',date'2016-10-01' ,80, 200 from dual union all
select 'Silver',date'2016-11-01' ,80, 200 from dual union all
select 'Silver',date'2016-12-01' ,80, 200 from dual union all
select 'Silver',date'2017-01-01' ,80, 200 from dual union all
select 'Silver',date'2017-02-01' ,80, 200 from dual union all
select 'Silver',date'2017-03-01' ,80, 200 from dual
)
,tmp1 as
(
select product,som,row_number() over (partition by product order by som) as rn,
RemainingNCustomerEOM,NCustomersSOM
from tmp
)
select P,D,r,n,ratio,som,r/n
from tmp1
model return updated rows
dimension by (product as P,rn as D)
measures (1 as ratio, RemainingNCustomerEOM as R,NCustomersSOM as N,som)
rules iterate (3)
(
ratio [P,D] order by P,D =nvl(R[CV(P),CV(D) - ITERATION_NUMBER ],1) / nvl(N[CV(P),CV(D)- ITERATION_NUMBER ],1) * ratio [cv(P),cv(D)]
) order by P,D
; |
|