swap everything for a 2109 baseline

This commit is contained in:
Paul Trowbridge 2023-03-07 16:45:55 -05:00
parent 15da8aecd4
commit 5e7ad3b208
4 changed files with 56 additions and 50 deletions

View File

@ -122,7 +122,7 @@ baseline 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
,'b23' "version" ,'b24' "version"
,'actuals' iter ,'actuals' iter
FROM FROM
rlarp.osm o rlarp.osm o
@ -135,11 +135,12 @@ baseline AS (
WHERE WHERE
( (
--base period orders booked.... --base period orders booked....
o.odate BETWEEN '2022-06-01' AND '2023-03-01' o.odate BETWEEN '2018-06-01' AND '2019-05-31'
--...or any open orders currently booked before cutoff.... --...or any open orders currently booked before cutoff....
OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2023-03-01') --OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2023-03-01')
--...or anything that shipped in that period --...or anything that shipped in that period
OR ((o.fspr BETWEEN '2301' AND '2309' OR o.fspr = '0000') AND o.sdate < '2023-03-01') --OR ((o.fspr BETWEEN '1901' AND '1912' OR o.fspr = '0000') AND o.sdate < '2023-03-01')
OR (o.fspr BETWEEN '1901' AND '1912')
) )
AND fs_line = '41010' AND fs_line = '41010'
AND calc_status <> 'CANCELED' AND calc_status <> 'CANCELED'
@ -272,15 +273,15 @@ baseline AS (
,o.calc_status ,o.calc_status
,o.flag ,o.flag
,o.odate + interval '1 year' odate ,o.odate + interval '1 year' odate
,o.oseas + 1 rseas ,o.oseas + 5 rseas
,o.rdate + interval '1 year' rdate ,o.rdate + interval '1 year' rdate
,o.rseas + 1 rseas ,o.rseas + 5 rseas
,o.pdate + interval '1 year' pdate ,o.pdate + interval '1 year' pdate
,o.pseas + 1 pseas ,o.pseas + 5 pseas
-----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
,'b23' "version" ,'b24' "version"
,'actuals_plug' iter ,'actuals_plug' iter
FROM FROM
rlarp.osm o rlarp.osm o
@ -289,15 +290,16 @@ baseline AS (
LEFT OUTER JOIN rlarp.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' false
AND fs_line = '41010' --o.odate BETWEEN '2022-03-01' AND '2022-05-31'
AND calc_status <> 'CANCELED' --AND fs_line = '41010'
AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER') --AND calc_status <> 'CANCELED'
--OR ( --AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
-- (o.fspr BETWEEN '2209' AND '2212' OR o.fspr = '0000') ----OR (
-- AND o.sdate BETWEEN '2022-03-01' AND '2022-05-31' ---- (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
,plnt ,plnt
@ -432,7 +434,7 @@ baseline 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
,'b23' "version" ,'b24' "version"
,'forecast_plug' iter ,'forecast_plug' iter
FROM FROM
rlarp.osmp o rlarp.osmp o
@ -479,11 +481,11 @@ SELECT
,o."dilin#" ,o."dilin#"
,o.quoten ,o.quoten
,o.quotel ,o.quotel
,o.dcodat + interval '1 year' --incremented ,o.dcodat + interval '5 years' --incremented
,o.ddqdat + interval '1 year' --incremented ,o.ddqdat + interval '5 years' --incremented
,o.dcmdat ,o.dcmdat
,o.fesdat ,o.fesdat
,o.dhidat + interval '1 year' --incremented ,o.dhidat + interval '5 years' --incremented
,o.fesind ,o.fesind
,o.dhpost ,o.dhpost
,gld.fspr --incremented ,gld.fspr --incremented
@ -567,22 +569,23 @@ SELECT
,o.fb_cst_loc_fut ,o.fb_cst_loc_fut
,o.calc_status ,o.calc_status
,o.flag ,o.flag
,o.odate + interval '1 year' --incremented ,o.odate + interval '5 years' --incremented
,o.oseas + 1 --incremented ,o.oseas + 5 --incremented
,o.rdate + interval '1 year' --incremented ,o.rdate + interval '5 years' --incremented
,o.rseas + 1 --incremented ,o.rseas + 5 --incremented
,o.pdate + interval '1 year' --incremented ,o.pdate + interval '5 years' --incremented
,o.pseas + 1 --incremented ,o.pseas + 5 --incremented
,o.sdate + interval '1 year' --incremented ,o.sdate + interval '5 years' --incremented
,o.sseas + 1 --incremented ,o.sseas + 5 --incremented
,'b23' "version" ,'b24' "version"
,'copy' iter ,'copy' iter
FROM FROM
baseline o baseline o
LEFT OUTER JOIN rlarp.gld ON LEFT OUTER JOIN rlarp.gld ON
(o.sdate + interval '1 year') BETWEEN gld.sdat and gld.edat (o.sdate + interval '5 years') BETWEEN gld.sdat and gld.edat
WHERE WHERE
o.odate + interval '1 year' >= '2023-06-01' true
--o.odate + interval '5 years' >= '2023-06-01'
) )
--INSERT INTO rlarp.osmf --INSERT INTO rlarp.osmf
SELECT SELECT

View File

@ -1,7 +1,8 @@
#!/bin/bash #!/bin/bash
#$PG -f ./build_stage.sql; #$PG -f ./build_stage.sql;
#$PG -f ./build_rolling.sql; #$PG -f ./build_rolling.sql;
$PG -f ./snap_itemm.sql; #$PF -f ./build_forecast.sql
$PG -f ./snap_cost_current.sql; $PG -f ./build/snap_itemm.sql;
$PG -f ./snap_customer.sql; $PG -f ./build/snap_cost_current.sql;
$PG -f ./build_pool.sql; $PG -f ./build/snap_customer.sql;
$PG -f ./build/build_pool.sql;

View File

@ -1,15 +1,16 @@
SELECT SELECT
--o.glec --o.glec
to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon') order_month to_char(CASE WHEN extract(month FROM o.odate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.odate),'FM00')||' - '||to_char(o.odate,'TMMon') order_month
,ROUND(SUM(fb_val_loc * r_rate) FILTER (WHERE oseas = 2023 AND iter = 'actuals'),0) act2023 ,ROUND(SUM(fb_val_loc * r_rate) FILTER (WHERE oseas = 2019 AND iter = 'actuals'),0) act2019
,ROUND(SUM(fb_val_loc * r_rate) FILTER (WHERE oseas = 2023 AND iter = 'actuals_plug'),0) act2023_plug ,ROUND(SUM(fb_val_loc * r_rate) FILTER (WHERE oseas = 2019 AND iter = 'actuals_plug'),0) act2019_plug
,ROUND(SUM(fb_val_loc * r_rate) FILTER (WHERE oseas = 2023 AND version IN ('actuals','15mo')),0) total_baseline ,ROUND(SUM(fb_val_loc * r_rate) FILTER (WHERE oseas = 2019 ),0) total_baseline
,ROUND(SUM(fb_val_loc * r_rate) FILTER (WHERE oseas = 2024 AND version = 'b23'),0) plan2024 ,ROUND(SUM(fb_val_loc * r_rate) FILTER (WHERE oseas = 2024 AND version = 'b24'),0) plan2024
,ROUND(SUM(fb_val_loc * r_rate) FILTER (WHERE oseas = 2024 ),0) full2024
FROM FROM
rlarp.osmfs o rlarp.osmf o
WHERE WHERE
oseas IN (2023,2024) --oseas IN (2023,2024)
AND substring(glec,1,1) <= '2' substring(glec,1,1) <= '2'
--AND quota_rep_descr = 'COLIN MAXWELL' --AND quota_rep_descr = 'COLIN MAXWELL'
GROUP BY GROUP BY
ROLLUP ( ROLLUP (

View File

@ -1,15 +1,16 @@
SELECT SELECT
--o.glec --o.glec
to_char(CASE WHEN extract(month FROM o.sdate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.sdate),'FM00')||' - '||to_char(o.sdate,'TMMon') order_month to_char(CASE WHEN extract(month FROM o.sdate) >= 6 THEN -5 ELSE 7 END + extract(month FROM o.sdate),'FM00')||' - '||to_char(o.sdate,'TMMon') order_month
,ROUND(SUM(fb_val_loc * r_rate) FILTER (WHERE sseas = 2023 AND version IN ('b23') AND iter = 'actuals'),0) act2023 ,ROUND(SUM(fb_val_loc * r_rate) FILTER (WHERE sseas = 2019 AND version IN ('b24') AND iter = 'actuals'),0) act2019
,ROUND(SUM(fb_val_loc * r_rate) FILTER (WHERE sseas = 2023 AND version IN ('b23') AND iter = 'actuals_plug'),0) act2023_plug --,ROUND(SUM(fb_val_loc * r_rate) FILTER (WHERE sseas = 2019 AND version IN ('b24') AND iter = 'actuals_plug'),0) act2019
,ROUND(SUM(fb_val_loc * r_rate) FILTER (WHERE sseas = 2023 AND version IN ('b23')),0) total_baseline ,ROUND(SUM(fb_val_loc * r_rate) FILTER (WHERE sseas = 2019 AND version IN ('b24')),0) total_baseline
,ROUND(SUM(fb_val_loc * r_rate) FILTER (WHERE sseas = 2024 AND version IN ('b23')),0) plan2024 ,ROUND(SUM(fb_val_loc * r_rate) FILTER (WHERE sseas = 2024 ),0) plan2024
FROM FROM
rlarp.osmfs o rlarp.osmf o
WHERE WHERE
sseas IN (2023,2024) true
AND substring(glec,1,1) <= '2' --sseas IN (2023,2024)
--AND substring(glec,1,1) <= '2'
--AND quota_rep_descr = 'COLIN MAXWELL' --AND quota_rep_descr = 'COLIN MAXWELL'
GROUP BY GROUP BY
ROLLUP ( ROLLUP (