use materialized view of itemm and use date range object to facilitate join
This commit is contained in:
parent
8d1cd1ade6
commit
8aeecc845b
@ -13,6 +13,7 @@ target AS (select $$replace_request$$::json def)
|
|||||||
,to_char(N1FSYP,'FM0000') FSPR
|
,to_char(N1FSYP,'FM0000') FSPR
|
||||||
,N1SD01 SDAT
|
,N1SD01 SDAT
|
||||||
,N1ED01 EDAT
|
,N1ED01 EDAT
|
||||||
|
,daterange(n1sd01, n1ed01) drange
|
||||||
,to_char(N1ED01,'yymm') CAPR
|
,to_char(N1ED01,'yymm') CAPR
|
||||||
,N1ED01 - N1SD01 +1 NDAYS
|
,N1ED01 - N1SD01 +1 NDAYS
|
||||||
,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR
|
,CASE WHEN EXTRACT(MONTH FROM N1ED01) >= 6 THEN EXTRACT(YEAR FROM N1ED01) + 1 ELSE EXTRACT(YEAR FROM N1ED01) END SSYR
|
||||||
@ -251,11 +252,11 @@ SELECT
|
|||||||
JOIN LATERAL json_to_record(ae.e) as jr(part_descr text, bill_cust_descr text, ship_cust_descr text, mix numeric) ON true
|
JOIN LATERAL json_to_record(ae.e) as jr(part_descr text, bill_cust_descr text, ship_cust_descr text, mix numeric) ON true
|
||||||
CROSS JOIN mxm
|
CROSS JOIN mxm
|
||||||
LEFT OUTER JOIN gld od ON
|
LEFT OUTER JOIN gld od ON
|
||||||
make_date(mxm.yr + 2021,mxm.cal,mxm.odom) BETWEEN od.sdat AND od.edat
|
od.drange @> make_date(mxm.yr + 2021,mxm.cal,mxm.odom)
|
||||||
LEFT OUTER JOIN gld rd ON
|
LEFT OUTER JOIN gld rd ON
|
||||||
make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag BETWEEN rd.sdat AND rd.edat
|
od.drange @> (make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag)
|
||||||
LEFT OUTER JOIN gld sd ON
|
LEFT OUTER JOIN gld sd ON
|
||||||
make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
|
od.drange @> (make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag + slag)
|
||||||
)
|
)
|
||||||
--SELECT * FROM basemix
|
--SELECT * FROM basemix
|
||||||
,log AS (
|
,log AS (
|
||||||
@ -336,7 +337,7 @@ SELECT
|
|||||||
FROM
|
FROM
|
||||||
basemix b
|
basemix b
|
||||||
CROSS JOIN log
|
CROSS JOIN log
|
||||||
LEFT OUTER JOIN rlarp.itemm i ON
|
LEFT OUTER JOIN rlarp.itemmv i ON
|
||||||
i.item = b.part
|
i.item = b.part
|
||||||
LEFT OUTER JOIN SEG ON
|
LEFT OUTER JOIN SEG ON
|
||||||
SEG.GLEC = i.glec
|
SEG.GLEC = i.glec
|
||||||
|
Loading…
Reference in New Issue
Block a user