From 960c02054d4f8b5522d240f7b842ccdf8ecc4621 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Tue, 5 Mar 2019 23:45:55 -0500 Subject: [PATCH] update price adjust to same logic as volume --- route_meta/addmonth_pd.sql | 56 +++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/route_meta/addmonth_pd.sql b/route_meta/addmonth_pd.sql index 6556105..d20833e 100644 --- a/route_meta/addmonth_pd.sql +++ b/route_meta/addmonth_pd.sql @@ -1,5 +1,27 @@ WITH target AS (select 50000 incr) +,GLD 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' +) ,mseq AS ( SELECT * FROM ( @@ -179,12 +201,12 @@ SELECT ,'b20' "version" --calculated ,'adjustment' iter --calculated ---------------ui columns------------------------- - ,null order_season - ,null order_month - ,null ship_season - ,null ship_month - ,null request_season - ,null request_month + ,null::numeric order_season + ,null::text order_month + ,null::numeric ship_season + ,null::text ship_month + ,null::numeric request_season + ,null::text request_month ,part_descr ,part_family ,part_group @@ -367,12 +389,14 @@ SELECT ,b.version --calculated ,b.iter --calculated -----------------------ui columns-------------------------------- - ,b.order_season - ,b.order_month - ,b.ship_season - ,b.ship_month - ,b.request_season - ,b.request_month + ,'adjust price' iterdet + ,null::jsonb iterdef + ,od.ssyr order_season + ,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom),'Mon') order_month + ,sd.ssyr ship_season + ,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag,'Mon') ship_month + ,rd.ssyr request_season + ,to_char(make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag,'Mon') request_month ,b.part_descr ,b.part_family ,b.part_group @@ -402,7 +426,13 @@ FROM CROSS JOIN mmixp m LEFT OUTER JOIN mseq ON mseq.m = m._month + LEFT OUTER JOIN gld od ON + make_date(mseq.yr + 2020,mseq.cal,m.odom) BETWEEN od.sdat AND od.edat + LEFT OUTER JOIN gld rd ON + make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag BETWEEN rd.sdat AND rd.edat + LEFT OUTER JOIN gld sd ON + make_date(mseq.yr + 2020,mseq.cal,m.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat WHERE m._month = 'Jul' ) -select sum(value_usd) from final \ No newline at end of file +INSERT INTO rlarp.osm_fcpool SELECT * FROM final RETURNING * \ No newline at end of file