functional but joining to itemm is very expensive
This commit is contained in:
parent
acca526dca
commit
8d1cd1ade6
@ -235,14 +235,14 @@ SELECT
|
||||
,substring(jr.part_descr,1,8) part_group
|
||||
,mxm.qty*mxm.momix*jr.mix units
|
||||
,mxm.amount*mxm.momix*jr.mix value_loc
|
||||
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) order_date
|
||||
,to_char(make_date(mxm.yr + 2020,mxm.cal,mxm.odom),'Mon') order_month
|
||||
,make_date(mxm.yr + 2021,mxm.cal,mxm.odom) order_date
|
||||
,to_char(make_date(mxm.yr + 2021,mxm.cal,mxm.odom),'Mon') order_month
|
||||
,od.ssyr order_season
|
||||
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag request_date
|
||||
,to_char(make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag,'Mon') request_month
|
||||
,make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag request_date
|
||||
,to_char(make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag,'Mon') request_month
|
||||
,rd.ssyr request_season
|
||||
,make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag + slag ship_date
|
||||
,to_char(make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag + slag,'Mon') ship_month
|
||||
,make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag + slag ship_date
|
||||
,to_char(make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag + slag,'Mon') ship_month
|
||||
,sd.ssyr ship_season
|
||||
,jr.mix
|
||||
FROM
|
||||
@ -251,11 +251,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
|
||||
CROSS JOIN mxm
|
||||
LEFT OUTER JOIN gld od ON
|
||||
make_date(mxm.yr + 2020,mxm.cal,mxm.odom) BETWEEN od.sdat AND od.edat
|
||||
make_date(mxm.yr + 2021,mxm.cal,mxm.odom) BETWEEN od.sdat AND od.edat
|
||||
LEFT OUTER JOIN gld rd ON
|
||||
make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag BETWEEN rd.sdat AND rd.edat
|
||||
make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag BETWEEN rd.sdat AND rd.edat
|
||||
LEFT OUTER JOIN gld sd ON
|
||||
make_date(mxm.yr + 2020,mxm.cal,mxm.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
|
||||
make_date(mxm.yr + 2021,mxm.cal,mxm.odom) + rlag + slag BETWEEN sd.sdat AND sd.edat
|
||||
)
|
||||
--SELECT * FROM basemix
|
||||
,log AS (
|
||||
@ -272,8 +272,8 @@ SELECT
|
||||
,(SELECT rcode FROM repc WHERE repp = log.doc->'scenario'->>'quota_rep_descr') dsm
|
||||
,log.doc->'scenario'->>'quota_rep_descr' quota_rep_descr
|
||||
,(SELECT director FROM repc WHERE repp = log.doc->'scenario'->>'quota_rep_descr') director
|
||||
,coalesce(cg.cgrp,bc.bvname) billto_group
|
||||
,coalesce(sg.cgrp,sc.bvname) shipto_group
|
||||
,CASE bc.BVADR6 WHEN '' THEN bc.BVNAME ELSE bc.BVADR6 END billto_group
|
||||
,CASE sc.BVADR6 WHEN '' THEN sc.BVNAME ELSE bc.BVADR6 END shipto_group
|
||||
,CASE SUBSTRING(bc.bvclas,2,3)
|
||||
--if the bill to class is ditsributor, then it's either warehouse or drop
|
||||
WHEN 'DIS' THEN
|
||||
@ -301,24 +301,24 @@ SELECT
|
||||
,b.part
|
||||
,b.part_descr
|
||||
,b.part_group
|
||||
,i.brnd branding
|
||||
,i.branding
|
||||
,i.majg||' - '||i.majgd majg_descr
|
||||
,i.ming||' - '||i.mingd ming_descr
|
||||
,i.majs||' - '||i.majsd majs_descr
|
||||
,i.mins||' - '||i.minsd mins_descr
|
||||
,seg.segm
|
||||
,b.fs_line --master data
|
||||
,'41010' fs_line --master data
|
||||
,bc.bvcurr r_currency --history cust mix
|
||||
,rx.rate r_rate --master data
|
||||
,copr.curr c_currency --master data
|
||||
,cx.rate c_rate --master data
|
||||
,b.units
|
||||
,b.value_loc
|
||||
,b.value_usd
|
||||
,b.value_loc * rx.rate value_usd
|
||||
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units cost_loc
|
||||
,COALESCE(im.cgstcs,ip.chstcs, ir.y0stcs)*b.units*cx.rate cost_loc
|
||||
,b.calc_status
|
||||
,b.flag
|
||||
,'CLOSED' calc_status
|
||||
,'SHIPMENT' flag
|
||||
,b.order_date
|
||||
,b.order_month
|
||||
,b.order_season
|
||||
@ -337,24 +337,24 @@ FROM
|
||||
basemix b
|
||||
CROSS JOIN log
|
||||
LEFT OUTER JOIN rlarp.itemm i ON
|
||||
i.itemm = b.part
|
||||
i.item = b.part
|
||||
LEFT OUTER JOIN SEG ON
|
||||
SEG.GLEC = i.glec
|
||||
--AND SEG.SEGM <> 'Other'
|
||||
LEFT OUTER JOIN LGDAT.CUST BC ON
|
||||
BC.BVCUST = b.BILL_CUST
|
||||
BC.BVCUST = rtrim(substring(b.bill_cust_descr,1,8))
|
||||
LEFT OUTER JOIN LGDAT.CUST SC ON
|
||||
SC.BVCUST = b.SHIP_CUST
|
||||
SC.BVCUST = rtrim(substring(b.ship_cust_descr,1,8))
|
||||
LEFT OUTER JOIN REPC ON
|
||||
REPC.RCODE = RTRIM(
|
||||
--retail items go to currep, or if null go to 90005
|
||||
CASE WHEN S.GLEC IN ('1RE','1CU') THEN
|
||||
CASE WHEN BVCTRY = 'CAN' THEN
|
||||
CASE WHEN i.glec IN ('1RE','1CU') THEN
|
||||
CASE WHEN bc.bvctry = 'CAN' THEN
|
||||
--Rachel Bowman
|
||||
'50300'
|
||||
ELSE
|
||||
--select customers go to select reps
|
||||
CASE ACCOUNT
|
||||
CASE CASE bc.BVADR6 WHEN '' THEN bc.BVNAME ELSE bc.BVADR6 END
|
||||
------Alecia Latini-------------------------------
|
||||
WHEN 'DO IT BEST' THEN '90006'
|
||||
WHEN 'ACE HARDWARE' THEN '90006'
|
||||
@ -379,14 +379,14 @@ FROM
|
||||
END
|
||||
--minor group b52 goes to dedicated rep
|
||||
ELSE
|
||||
CASE WHEN MING = 'B52' THEN
|
||||
CASE WHEN i.MING = 'B52' THEN
|
||||
'PW'
|
||||
--gdir, ndir go to bill-to rep
|
||||
ELSE
|
||||
CASE WHEN BILL_CLASS IN ('GDIR','NDIR') THEN
|
||||
BILL_REP
|
||||
CASE WHEN bc.bvclas IN ('GDIR','NDIR') THEN
|
||||
bc.bvsalm
|
||||
ELSE
|
||||
SHIP_REP
|
||||
sc.bvsalm
|
||||
END
|
||||
END
|
||||
END
|
||||
@ -401,7 +401,7 @@ FROM
|
||||
ir.y0part = b.part
|
||||
AND ir.y0plnt = i.dplt
|
||||
LEFT OUTER JOIN lgdat.plnt ON
|
||||
yaplnt = a.v6plnt
|
||||
yaplnt = i.dplt
|
||||
LEFT OUTER JOIN copr ON
|
||||
copr.comp = yacomp::text
|
||||
LEFT OUTER JOIN rlarp.ffcret cx ON
|
||||
|
Loading…
Reference in New Issue
Block a user