テストデータを取得するために、SQLクエリを必要とする
with t(year, Week , Item, Location, stock_on_hand) as
(select 2016, 01, 'I1', 'L1', 50 from dual union all
select 2016, 02, 'I1', 'L1', 30 from dual union all
select 2016 ,05, 'I1', 'L1', 60 from dual union all
select 2016 ,08, 'I1', 'L1', 50 from dual union all
select 2016, 02, 'I2', 'L1', 30 from dual union all
select 2016, 08, 'I2', 'L1', 40 from dual union all
select 2016, 02, 'I1', 'L2', 10 from dual union all
select 2016, 08, 'I1', 'L2', 40 from dual union all
select 2016, 08, 'I1', 'L3', 40 from dual)
クエリ
with t(year, Week , Item, Location, stock_on_hand) as
(select 2016, 01, 'I1', 'L1', 50 from dual union all
select 2016, 02, 'I1', 'L1', 30 from dual union all
select 2016 ,05, 'I1', 'L1', 60 from dual union all
select 2016 ,08, 'I1', 'L1', 50 from dual union all
select 2016, 02, 'I2', 'L1', 30 from dual union all
select 2016, 08, 'I2', 'L1', 40 from dual union all
select 2016, 02, 'I1', 'L2', 10 from dual union all
select 2016, 08, 'I1', 'L2', 40 from dual union all
select 2016, 08, 'I1', 'L3', 40 from dual),
temp(year, Week , Item, Location, stock_on_hand, ct) as(
select year, Week , Item, Location, stock_on_hand, nvl(lead(Week) over(partition by Item, Location order by year, Week)-Week,1) from t)
select year, Week + rn - 1 as week, Item, Location, stock_on_hand
from temp, xmltable('1 to xs:integer($ct)' passing ct as "ct" columns rn number path '.')
order by Item, Location ,year, week
このappr oachにも1つのマイナーがあります。別の年に間隔がある場合。 Ex
select 2016, 01, 'I1', 'L1', 50 from dual union all
select 2017, 02, 'I1', 'L1', 30 from dual union all
次に正しく動作しません。私はあなたのデータが同じパターンを持っているかどうかはわかりません。それがあれば、投稿または回答する情報を追加してください。数年に住んでいる間隔については
UPDATE あなたがフォローを行うことができます(たstartDateのために私は国際週の日付を選択します)
with t(dateStart , Item, Location, stock_on_hand) as
(select to_date('28/12/2015', 'dd-mm-yyyy'), 'I1', 'L1', 50 from dual union all
select to_date('04/01/2016', 'dd-mm-yyyy'), 'I1', 'L1', 30 from dual union all
select to_date('25/01/2016', 'dd-mm-yyyy'), 'I1', 'L1', 60 from dual union all
select to_date('15/02/2016', 'dd-mm-yyyy'), 'I1', 'L1', 50 from dual union all
select to_date('01/01/2018', 'dd-mm-yyyy'), 'I1', 'L1', 30 from dual union all
select to_date('04/01/2016', 'dd-mm-yyyy'), 'I2', 'L1', 40 from dual union all
select to_date('15/02/2016', 'dd-mm-yyyy'), 'I2', 'L1', 10 from dual union all
select to_date('04/01/2016', 'dd-mm-yyyy'), 'I1', 'L2', 30 from dual union all
select to_date('15/02/2016', 'dd-mm-yyyy'), 'I1', 'L2', 40 from dual union all
select to_date('15/02/2016', 'dd-mm-yyyy'), 'I1', 'L3', 40 from dual),
temp(dateStart, Item, Location, stock_on_hand, ct) as(
select dateStart , Item, Location, stock_on_hand, nvl((lead(dateStart) over(partition by Item, Location order by dateStart)-dateStart)/7,1) from t)
select dateStart + (rn - 1)*7 as week, Item, Location, stock_on_hand
from temp, xmltable('1 to xs:integer($ct)' passing ct as "ct" columns rn number path '.')
order by Item, Location , dateStart