change version to b23
This commit is contained in:
parent
a0c5482f6c
commit
0ae9f604c1
@ -1,33 +1,18 @@
|
|||||||
-- Connection: usmidsap01.ubm
|
-- Connection: usmidsap01.ubm
|
||||||
--\timing
|
--\timing
|
||||||
|
|
||||||
|
/*----------------------------------------------------------------------------------------
|
||||||
|
1. copy existing actuals for the current season (which is incomplete)
|
||||||
|
* for example 6/1/22 -> 3/7/23
|
||||||
|
2. fill out a full year of history by going back 2 years to get 3/8/22 -> 5/31/22
|
||||||
|
3. stack the results of 1 & 2 and increment all rows by 1 year
|
||||||
|
*/----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
TRUNCATE TABLE rlarp.osmf;
|
TRUNCATE TABLE rlarp.osmf;
|
||||||
|
|
||||||
INSERT INTO rlarp.osmf
|
INSERT INTO rlarp.osmf
|
||||||
WITH
|
WITH
|
||||||
gld AS (
|
baseline AS (
|
||||||
SELECT
|
|
||||||
N1COMP COMP
|
|
||||||
,N1CCYY FSYR
|
|
||||||
,KPMAXP PERDS
|
|
||||||
,N1FSPP PERD
|
|
||||||
,to_char(N1FSYP,'FM0000') FSPR
|
|
||||||
,N1SD01 SDAT
|
|
||||||
,N1ED01 EDAT
|
|
||||||
,to_char(N1ED01,'yymm') CAPR
|
|
||||||
,N1ED01 - N1SD01 +1 NDAYS
|
|
||||||
,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR
|
|
||||||
,to_char(CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(MONTH FROM N1ED01) -5 ELSE EXTRACT(MONTH FROM N1ED01) +7 END,'00') SSPR
|
|
||||||
FROM
|
|
||||||
LGDAT.GLDATREF
|
|
||||||
INNER JOIN LGDAT.GLDATE ON
|
|
||||||
KPCOMP = N1COMP AND
|
|
||||||
KPCCYY = N1CCYY
|
|
||||||
WHERE
|
|
||||||
N1COMP = 93
|
|
||||||
--AND DIGITS(N1FSYP) = '1901'
|
|
||||||
)
|
|
||||||
--SELECT * FROM gld
|
|
||||||
,baseline AS (
|
|
||||||
SELECT
|
SELECT
|
||||||
-----------documents-------------
|
-----------documents-------------
|
||||||
null::int "ddord#"
|
null::int "ddord#"
|
||||||
@ -137,15 +122,15 @@ gld AS (
|
|||||||
-----when null, greatest/least is just going to act like coalesce
|
-----when null, greatest/least is just going to act like coalesce
|
||||||
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
|
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
|
||||||
,ss.ssyr sseas
|
,ss.ssyr sseas
|
||||||
,'15mo' "version"
|
,'b23' "version"
|
||||||
,'actuals' iter
|
,'actuals' iter
|
||||||
FROM
|
FROM
|
||||||
rlarp.osm o
|
rlarp.osm o
|
||||||
--snap the ship dates of the historic fiscal period
|
--snap the ship dates of the historic fiscal period
|
||||||
LEFT OUTER JOIN gld ON
|
LEFT OUTER JOIN rlarp.gld ON
|
||||||
gld.fspr = o.fspr
|
gld.fspr = o.fspr
|
||||||
--get the shipping season for open orders based on the snapped date
|
--get the shipping season for open orders based on the snapped date
|
||||||
LEFT OUTER JOIN gld ss ON
|
LEFT OUTER JOIN rlarp.gld ss ON
|
||||||
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
|
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
|
||||||
WHERE
|
WHERE
|
||||||
(
|
(
|
||||||
@ -295,19 +280,23 @@ gld AS (
|
|||||||
-----when null, greatest/least is just going to act like coalesce
|
-----when null, greatest/least is just going to act like coalesce
|
||||||
,greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' sdate
|
,greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' sdate
|
||||||
,ss.ssyr sseas
|
,ss.ssyr sseas
|
||||||
,'actuals' "version"
|
,'b23' "version"
|
||||||
,'actuals_plug' iter
|
,'actuals_plug' iter
|
||||||
FROM
|
FROM
|
||||||
rlarp.osm o
|
rlarp.osm o
|
||||||
LEFT OUTER JOIN gld ON
|
LEFT OUTER JOIN rlarp.gld ON
|
||||||
gld.fspr = o.fspr
|
gld.fspr = o.fspr
|
||||||
LEFT OUTER JOIN gld ss ON
|
LEFT OUTER JOIN rlarp.gld ss ON
|
||||||
greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat
|
greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat
|
||||||
WHERE
|
WHERE
|
||||||
o.odate BETWEEN '2022-03-01' AND '2022-05-31'
|
o.odate BETWEEN '2022-03-01' AND '2022-05-31'
|
||||||
AND fs_line = '41010'
|
AND fs_line = '41010'
|
||||||
AND calc_status <> 'CANCELED'
|
AND calc_status <> 'CANCELED'
|
||||||
------exclude actuals for now and use forecast to get the plug for the rest of the year
|
AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
|
||||||
|
--OR (
|
||||||
|
-- (o.fspr BETWEEN '2209' AND '2212' OR o.fspr = '0000')
|
||||||
|
-- AND o.sdate BETWEEN '2022-03-01' AND '2022-05-31'
|
||||||
|
--)
|
||||||
AND version = 'ACTUALS'
|
AND version = 'ACTUALS'
|
||||||
GROUP BY
|
GROUP BY
|
||||||
o.fspr
|
o.fspr
|
||||||
@ -443,13 +432,13 @@ gld AS (
|
|||||||
-----when null, greatest/least is just going to act like coalesce
|
-----when null, greatest/least is just going to act like coalesce
|
||||||
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
|
,greatest(least(o.sdate,gld.edat),gld.sdat) sdate
|
||||||
,ss.ssyr sseas
|
,ss.ssyr sseas
|
||||||
,'actuals' "version"
|
,'b23' "version"
|
||||||
,'forecast_plug' iter
|
,'forecast_plug' iter
|
||||||
FROM
|
FROM
|
||||||
rlarp.osmp o
|
rlarp.osmp o
|
||||||
LEFT OUTER JOIN gld ON
|
LEFT OUTER JOIN rlarp.gld ON
|
||||||
gld.fspr = o.fspr
|
gld.fspr = o.fspr
|
||||||
LEFT OUTER JOIN gld ss ON
|
LEFT OUTER JOIN rlarp.gld ss ON
|
||||||
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
|
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
|
||||||
WHERE
|
WHERE
|
||||||
false
|
false
|
||||||
@ -479,6 +468,7 @@ gld AS (
|
|||||||
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
,greatest(least(o.sdate,gld.edat),gld.sdat)
|
||||||
,ss.ssyr
|
,ss.ssyr
|
||||||
)
|
)
|
||||||
|
----------increment the baseline selection---------------------
|
||||||
,incr AS (
|
,incr AS (
|
||||||
SELECT
|
SELECT
|
||||||
o."ddord#"
|
o."ddord#"
|
||||||
@ -589,8 +579,8 @@ SELECT
|
|||||||
,'copy' iter
|
,'copy' iter
|
||||||
FROM
|
FROM
|
||||||
baseline o
|
baseline o
|
||||||
LEFT OUTER JOIN gld ON
|
LEFT OUTER JOIN rlarp.gld ON
|
||||||
o.sdate + interval '1 year' BETWEEN gld.sdat and gld.edat
|
(o.sdate + interval '1 year') BETWEEN gld.sdat and gld.edat
|
||||||
WHERE
|
WHERE
|
||||||
o.odate + interval '1 year' >= '2023-06-01'
|
o.odate + interval '1 year' >= '2023-06-01'
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user