work on clean up and getting in sync with sales matrix update branch
This commit is contained in:
parent
97beed28fd
commit
8ddca29849
@ -1,70 +0,0 @@
|
||||
|
||||
set work_mem TO '4GB';
|
||||
|
||||
DROP TABLE IF EXISTS rlarp.live_quotes_review_mv;
|
||||
CREATE TABLE rlarp.live_quotes_review_mv AS
|
||||
WITH
|
||||
lq AS MATERIALIZED (
|
||||
SELECT
|
||||
lq.*
|
||||
,substring(lq.part,1,8) mold
|
||||
FROM
|
||||
pricequote.live_quotes lq
|
||||
)
|
||||
,lqg AS (
|
||||
SELECT
|
||||
lq.*
|
||||
,pricing->'product'->>'mold' part_group
|
||||
,substring(pricing->'customer'->>'chan',1,1) qchan
|
||||
,pricing->'customer'->>'cust' qcust
|
||||
,pricing->'product'->>'itemrel' item_fit
|
||||
,(pricing->'product'->>'pltq')::numeric pltq
|
||||
,(pricing->'guidance'->'finalPrice'->>'Price')::numeric guidance
|
||||
,pricing->'guidance'->'finalPrice'->>'Reason' reason
|
||||
,(pricing->'product'->>'cstd_usd_ina')::numeric fstd_usd
|
||||
,(pricing->'guidance'->>'ltp')::numeric ltp
|
||||
,(pricing->'guidance'->>'optimization')::numeric optimization
|
||||
,(pricing->'guidance'->>'inflationFactor')::numeric inflation
|
||||
,jsonb_pretty(pricing) pricing
|
||||
FROM
|
||||
lq
|
||||
LEFT JOIN LATERAL rlarp.guidance_r1(
|
||||
rlarp.get_guidance_dseg(lq.billto,lq.shipto,substring(lq.part,1,8),lq.v1ds,lq.units_each,2024)
|
||||
) pricing ON TRUE
|
||||
WHERE
|
||||
lq.qstat ~ 'Submitted'
|
||||
)
|
||||
,hist AS (
|
||||
SELECT
|
||||
g.*
|
||||
,gset.chan
|
||||
--,gset.mold moldh
|
||||
,gset.v1ds v1dsh
|
||||
,gset.cust
|
||||
,gset.vers
|
||||
,je.k
|
||||
,seas.*
|
||||
FROM
|
||||
lqg g
|
||||
LEFT OUTER JOIN rlarp.price_pool_dev p ON
|
||||
p.gset @> jsonb_build_object('mold',g.part_group)
|
||||
AND p.gset ? 'cust'
|
||||
AND p.gset ? 'v1ds'
|
||||
LEFT JOIN LATERAL jsonb_to_record(p.gset) AS gset(
|
||||
chan text
|
||||
,mold text
|
||||
,v1ds text
|
||||
,v0ds text
|
||||
,cust text
|
||||
,vers text
|
||||
--,nurs text
|
||||
--,ghse text
|
||||
) ON TRUE
|
||||
LEFT JOIN LATERAL jsonb_each(p.season) je(k,v) on true
|
||||
LEFT JOIN Lateral jsonb_to_record(je.v) as seas(
|
||||
units numeric
|
||||
,sales_usd numeric
|
||||
,price_usd numeric
|
||||
) ON TRUE
|
||||
)
|
||||
SELECT * FROM hist;
|
@ -10,7 +10,7 @@ SELECT
|
||||
,je.k
|
||||
,seas.*
|
||||
FROM
|
||||
rlarp.price_pool_dev p
|
||||
rlarp.price_pool p
|
||||
LEFT JOIN LATERAL jsonb_to_record(p.gset) AS gset(
|
||||
chan text
|
||||
,mold text
|
||||
|
@ -18,7 +18,7 @@ sort AS (
|
||||
,stats.*
|
||||
,season
|
||||
FROM
|
||||
rlarp.price_pool_dev p
|
||||
rlarp.price_pool p
|
||||
JOIN LATERAL jsonb_to_record(gset) AS gset(
|
||||
chan text
|
||||
,mold text
|
||||
|
@ -11,7 +11,7 @@ sel AS (select 'v1:T..PLT..' _v1ds, 'KAWAHARA NURSERY' _cust, 'AZE10001' _mold,
|
||||
,stats.*
|
||||
,season
|
||||
FROM
|
||||
rlarp.price_pool_dev p
|
||||
rlarp.price_pool p
|
||||
CROSS JOIN sel
|
||||
JOIN LATERAL jsonb_to_record(gset) AS gset(
|
||||
chan text
|
||||
|
@ -25,7 +25,7 @@ BEGIN
|
||||
stats,
|
||||
(SELECT doc FROM getj) AS gdoc
|
||||
FROM
|
||||
rlarp.price_pool_dev p
|
||||
rlarp.price_pool p
|
||||
WHERE
|
||||
gset @> jsonb_build_object(
|
||||
'mold', (SELECT doc->>'mold' FROM getj),
|
||||
|
@ -10,7 +10,7 @@ sel AS (select 'v1:P.P.PLT..' _v1ds, 'ALTMAN PLANTS' _cust, 'TFR001G0' _mold, 'D
|
||||
,row_number() OVER (PARTITION BY p.agglevel ORDER BY avgunits DESC) rn
|
||||
,stats.*
|
||||
FROM
|
||||
rlarp.price_pool_dev p
|
||||
rlarp.price_pool p
|
||||
CROSS JOIN sel
|
||||
JOIN LATERAL jsonb_to_record(gset) AS gset(
|
||||
chan text
|
||||
|
@ -1,69 +0,0 @@
|
||||
DROP TABLE IF EXISTS rlarp.live_quotes_nohist;
|
||||
|
||||
CREATE TABLE rlarp.live_quotes_nohist AS
|
||||
WITH
|
||||
lq AS MATERIALIZED (
|
||||
SELECT
|
||||
lq.*
|
||||
,substring(lq.part,1,8) mold
|
||||
FROM
|
||||
pricequote.live_quotes lq
|
||||
)
|
||||
,lqg AS (
|
||||
SELECT
|
||||
lq.*
|
||||
,pricing->'product'->>'mold' part_group
|
||||
,substring(pricing->'customer'->>'chan',1,1) qchan
|
||||
,pricing->'customer'->>'cust' qcust
|
||||
,pricing->'product'->>'itemrel' item_fit
|
||||
,(pricing->'product'->>'pltq')::numeric pltq
|
||||
,(pricing->'guidance'->'finalPrice'->>'Price')::numeric guidance
|
||||
,pricing->'guidance'->'finalPrice'->>'Reason' reason
|
||||
,(pricing->'product'->>'cstd_usd_ina')::numeric fstd_usd
|
||||
,(pricing->'guidance'->>'ltp')::numeric ltp
|
||||
,(pricing->'guidance'->>'optimization')::numeric optimization
|
||||
,(pricing->'guidance'->>'inflationFactor')::numeric inflation
|
||||
,jsonb_pretty(pricing) pricing
|
||||
FROM
|
||||
lq
|
||||
LEFT JOIN LATERAL rlarp.guidance_r1(
|
||||
rlarp.get_guidance_dseg(lq.billto,lq.shipto,substring(lq.part,1,8),lq.v1ds,lq.units_each,2024)
|
||||
) pricing ON TRUE
|
||||
WHERE
|
||||
TRUE
|
||||
--lq.qstat ~ 'Submitted'
|
||||
)
|
||||
--,hist AS (
|
||||
-- SELECT
|
||||
-- g.*
|
||||
-- ,gset.chan
|
||||
-- --,gset.mold moldh
|
||||
-- ,gset.v1ds v1dsh
|
||||
-- ,gset.cust
|
||||
-- ,gset.vers
|
||||
-- ,je.k
|
||||
-- ,seas.*
|
||||
-- FROM
|
||||
-- lqg g
|
||||
-- LEFT OUTER JOIN rlarp.price_pool_dev p ON
|
||||
-- p.gset @> jsonb_build_object('mold',g.part_group)
|
||||
-- AND p.gset ? 'cust'
|
||||
-- AND p.gset ? 'v1ds'
|
||||
-- LEFT JOIN LATERAL jsonb_to_record(p.gset) AS gset(
|
||||
-- chan text
|
||||
-- ,mold text
|
||||
-- ,v1ds text
|
||||
-- ,v0ds text
|
||||
-- ,cust text
|
||||
-- ,vers text
|
||||
-- --,nurs text
|
||||
-- --,ghse text
|
||||
-- ) ON TRUE
|
||||
-- LEFT JOIN LATERAL jsonb_each(p.season) je(k,v) on true
|
||||
-- LEFT JOIN Lateral jsonb_to_record(je.v) as seas(
|
||||
-- units numeric
|
||||
-- ,sales_usd numeric
|
||||
-- ,price_usd numeric
|
||||
-- ) ON TRUE
|
||||
--)
|
||||
SELECT * FROM lqg;
|
@ -46,7 +46,7 @@ lq AS MATERIALIZED (
|
||||
,seas.*
|
||||
FROM
|
||||
lqg g
|
||||
LEFT OUTER JOIN rlarp.price_pool_dev p ON
|
||||
LEFT OUTER JOIN rlarp.price_pool p ON
|
||||
p.gset @> jsonb_build_object('mold',g.part_group)
|
||||
AND p.gset ? 'cust'
|
||||
AND p.gset ? 'v1ds'
|
||||
|
@ -1,59 +0,0 @@
|
||||
WITH
|
||||
lq AS MATERIALIZED (
|
||||
SELECT
|
||||
lq.*
|
||||
,substring(lq.part,1,8) mold
|
||||
FROM
|
||||
pricequote.live_quotes lq
|
||||
)
|
||||
,lqg AS (
|
||||
SELECT
|
||||
lq.*
|
||||
,m.part_group
|
||||
,(pricing->'guidance'->'finalPrice'->>'Price')::numeric guidance
|
||||
,pricing->'guidance'->'finalPrice'->>'Reason' reason
|
||||
,jsonb_pretty(pricing) pricing
|
||||
FROM
|
||||
lq
|
||||
JOIN LATERAL rlarp.guidance_r1(
|
||||
rlarp.get_guidance_dseg(lq.billto,lq.shipto,substring(lq.part,1,8),lq.v1ds,lq.units_each,2024)
|
||||
) pricing ON TRUE
|
||||
LEFT OUTER JOIN rlarp.molds m ON
|
||||
m.stlc = lq.mold
|
||||
WHERE
|
||||
lq.qstat ~ 'Submitted'
|
||||
)
|
||||
,hist AS (
|
||||
SELECT
|
||||
g.*
|
||||
,gset.chan
|
||||
--,gset.mold moldh
|
||||
,gset.v1ds v1dsh
|
||||
,gset.cust
|
||||
,gset.vers
|
||||
,je.k
|
||||
,seas.*
|
||||
FROM
|
||||
lqg g
|
||||
LEFT OUTER JOIN rlarp.price_pool_dev p ON
|
||||
p.gset @> jsonb_build_object('mold',g.part_group)
|
||||
AND p.gset ? 'cust'
|
||||
AND p.gset ? 'v1ds'
|
||||
LEFT JOIN LATERAL jsonb_to_record(p.gset) AS gset(
|
||||
chan text
|
||||
,mold text
|
||||
,v1ds text
|
||||
,v0ds text
|
||||
,cust text
|
||||
,vers text
|
||||
--,nurs text
|
||||
--,ghse text
|
||||
) ON TRUE
|
||||
LEFT JOIN LATERAL jsonb_each(p.season) je(k,v) on true
|
||||
LEFT JOIN Lateral jsonb_to_record(je.v) as seas(
|
||||
units numeric
|
||||
,sales_usd numeric
|
||||
,price_usd numeric
|
||||
) ON TRUE
|
||||
)
|
||||
SELECT * FROM hist WHERE qid = 73059
|
@ -2,9 +2,9 @@
|
||||
--LANGUAGE plpgsql AS
|
||||
--$func$
|
||||
--BEGIN;
|
||||
DROP MATERIALIZED VIEW IF EXISTS rlarp.price_pool_dev CASCADE;
|
||||
--CREATE TABLE IF NOT EXISTS rlarp.price_pool_dev AS (
|
||||
CREATE MATERIALIZED VIEW rlarp.price_pool_dev AS (
|
||||
-- DROP MATERIALIZED VIEW IF EXISTS rlarp.price_pool CASCADE;
|
||||
--CREATE TABLE IF NOT EXISTS rlarp.price_pool AS (
|
||||
CREATE MATERIALIZED VIEW rlarp.price_pool AS (
|
||||
WITH
|
||||
agg AS (
|
||||
SELECT
|
||||
@ -12,13 +12,13 @@ CREATE MATERIALIZED VIEW rlarp.price_pool_dev AS (
|
||||
,substring(o.version,1,1) version
|
||||
,o.chanwide
|
||||
,o.nursery_region
|
||||
,c.greenhouse_region
|
||||
,m.part_group baseitem
|
||||
,m.majg
|
||||
,m.assc
|
||||
,i.coltier
|
||||
,'v1:' || rtrim(COALESCE(i.coltier, ''))|| '.' || rtrim(substring(COALESCE(i.branding, ''), 1, 1))|| '.' || rtrim(COALESCE(i.uomp, ''))|| '.' || rtrim(COALESCE(i.suffix, ''))|| '.' || rtrim(COALESCE(i.accs_ps, '')) v1dataseg
|
||||
,_ds.dataseg v0dataseg
|
||||
,o.greenhouse_region
|
||||
,o.partgroup baseitem
|
||||
,o.majg
|
||||
,o.assc
|
||||
,o.coltier
|
||||
,o.dataseg v1dataseg
|
||||
,o.v0dataseg v0dataseg
|
||||
,o.oseas oseas
|
||||
,round(sum(o.qty),0) units
|
||||
,round(sum(o.sales_usd),0) sales_usd
|
||||
@ -26,35 +26,26 @@ CREATE MATERIALIZED VIEW rlarp.price_pool_dev AS (
|
||||
,count(DISTINCT o.ordnum) ordcount
|
||||
FROM
|
||||
rlarp.osm_stack o
|
||||
INNER JOIN "CMS.CUSLG".itemm i ON
|
||||
i.item = o.part
|
||||
LEFT OUTER JOIN rlarp.molds m ON
|
||||
m.stlc = i.stlc
|
||||
LEFT OUTER JOIN _ds ON
|
||||
_ds.colgrp = o.colgrp
|
||||
AND _ds.brand = substring(i.branding,1,1)
|
||||
LEFT OUTER JOIN pricequote.market_setavgprice tp ON
|
||||
tp.season = (SELECT ssyr FROM rlarp.gld where drange @> current_date)
|
||||
AND tp.country = 'ALL'
|
||||
AND tp.geo = 'ALL'
|
||||
AND tp.region = 'ALL'
|
||||
AND tp.mold = i.stlc
|
||||
AND tp.mold = o.stlc
|
||||
AND tp.chan = 'DISTRIB DROP SHIP'
|
||||
AND tp.data_segment = 'v1:' || rtrim(COALESCE(i.coltier, ''))|| '.' || rtrim(substring(COALESCE(i.branding, ''), 1, 1))|| '.' || rtrim(COALESCE(i.uomp, ''))|| '.' || rtrim(COALESCE(i.suffix, ''))|| '.' || rtrim(COALESCE(i.accs_ps, ''))
|
||||
AND tp.data_segment = o.dataseg
|
||||
LEFT OUTER JOIN pricequote.market_setavgprice tq ON
|
||||
tq.season = (SELECT ssyr FROM rlarp.gld where drange @> current_date)
|
||||
AND tq.country = 'ALL'
|
||||
AND tq.geo = 'ALL'
|
||||
AND tq.region = 'ALL'
|
||||
AND tq.mold = i.stlc
|
||||
AND tq.mold = o.stlc
|
||||
AND tq.chan = 'DISTRIB DROP SHIP'
|
||||
AND tq.data_segment = _ds.dataseg
|
||||
LEFT OUTER JOIN rlarp.cust c ON
|
||||
c.code = CASE o.chan WHEN 'DIR' THEN o.bill_cust ELSE o.ship_cust END
|
||||
AND tq.data_segment = o.v0dataseg
|
||||
WHERE
|
||||
o.version IN ('Actual','Quotes')
|
||||
AND o.oseas >= 2015
|
||||
AND o.dsm <> 'PW'
|
||||
AND o.ming <> 'B52'
|
||||
--AND o.part like 'SQL035%'
|
||||
--AND o.calc_status <> 'CANCELED'
|
||||
--AND o.fs_line = '41010'
|
||||
@ -65,13 +56,13 @@ CREATE MATERIALIZED VIEW rlarp.price_pool_dev AS (
|
||||
,substring(o.version,1,1)
|
||||
,o.chanwide
|
||||
,o.nursery_region
|
||||
,c.greenhouse_region
|
||||
,m.part_group
|
||||
,m.majg
|
||||
,m.assc
|
||||
,i.coltier
|
||||
,'v1:' || rtrim(COALESCE(i.coltier, ''))|| '.' || rtrim(substring(COALESCE(i.branding, ''), 1, 1))|| '.' || rtrim(COALESCE(i.uomp, ''))|| '.' || rtrim(COALESCE(i.suffix, ''))|| '.' || rtrim(COALESCE(i.accs_ps, ''))
|
||||
,_ds.dataseg
|
||||
,o.greenhouse_region
|
||||
,o.partgroup
|
||||
,o.majg
|
||||
,o.assc
|
||||
,o.coltier
|
||||
,o.dataseg
|
||||
,o.v0dataseg
|
||||
,o.oseas
|
||||
HAVING
|
||||
round(sum(o.qty),0) > 0
|
||||
@ -82,49 +73,40 @@ CREATE MATERIALIZED VIEW rlarp.price_pool_dev AS (
|
||||
,substring(o.version,1,1) version
|
||||
,o.chanwide
|
||||
,o.nursery_region
|
||||
,c.greenhouse_region
|
||||
,m.part_group baseitem
|
||||
,m.majg
|
||||
,m.assc
|
||||
,i.coltier
|
||||
,'v1:' || rtrim(COALESCE(i.coltier, ''))|| '.' || rtrim(substring(COALESCE(i.branding, ''), 1, 1))|| '.' || rtrim(COALESCE(i.uomp, ''))|| '.' || rtrim(COALESCE(i.suffix, ''))|| '.' || rtrim(COALESCE(i.accs_ps, '')) v1dataseg
|
||||
,_ds.dataseg v0dataseg
|
||||
,0 oseas
|
||||
,o.greenhouse_region
|
||||
,o.partgroup baseitem
|
||||
,o.majg
|
||||
,o.assc
|
||||
,o.coltier
|
||||
,o.dataseg v1dataseg
|
||||
,o.v0dataseg v0dataseg
|
||||
,o.oseas oseas
|
||||
,round(sum(o.qty),0) units
|
||||
,round(sum(o.sales_usd),0) sales_usd
|
||||
,round(sum(COALESCE(tp.target_price,tq.target_price) * o.qty),2) target_price
|
||||
,count(DISTINCT o.ordnum) ordcount
|
||||
FROM
|
||||
rlarp.osm_stack o
|
||||
INNER JOIN "CMS.CUSLG".itemm i ON
|
||||
i.item = o.part
|
||||
LEFT OUTER JOIN rlarp.molds m ON
|
||||
m.stlc = i.stlc
|
||||
LEFT OUTER JOIN _ds ON
|
||||
_ds.colgrp = o.colgrp
|
||||
AND _ds.brand = substring(i.branding,1,1)
|
||||
LEFT OUTER JOIN pricequote.market_setavgprice tp ON
|
||||
tp.season = (SELECT ssyr FROM rlarp.gld where drange @> current_date)
|
||||
AND tp.country = 'ALL'
|
||||
AND tp.geo = 'ALL'
|
||||
AND tp.region = 'ALL'
|
||||
AND tp.mold = i.stlc
|
||||
AND tp.mold = o.stlc
|
||||
AND tp.chan = 'DISTRIB DROP SHIP'
|
||||
AND tp.data_segment = 'v1:' || rtrim(COALESCE(i.coltier, ''))|| '.' || rtrim(substring(COALESCE(i.branding, ''), 1, 1))|| '.' || rtrim(COALESCE(i.uomp, ''))|| '.' || rtrim(COALESCE(i.suffix, ''))|| '.' || rtrim(COALESCE(i.accs_ps, ''))
|
||||
AND tp.data_segment = o.dataseg
|
||||
LEFT OUTER JOIN pricequote.market_setavgprice tq ON
|
||||
tq.season = (SELECT ssyr FROM rlarp.gld where drange @> current_date)
|
||||
AND tq.country = 'ALL'
|
||||
AND tq.geo = 'ALL'
|
||||
AND tq.region = 'ALL'
|
||||
AND tq.mold = i.stlc
|
||||
AND tq.mold = o.stlc
|
||||
AND tq.chan = 'DISTRIB DROP SHIP'
|
||||
AND tq.data_segment = _ds.dataseg
|
||||
LEFT OUTER JOIN rlarp.cust c ON
|
||||
c.code = CASE o.chan WHEN 'DIR' THEN o.bill_cust ELSE o.ship_cust END
|
||||
AND tq.data_segment = o.v0dataseg
|
||||
WHERE
|
||||
o.version IN ('Actual','Quotes')
|
||||
AND o.odate >= current_date - '4 months'::interval
|
||||
AND o.dsm <> 'PW'
|
||||
AND o.ming <> 'B52'
|
||||
--AND o.part like 'SQL035%'
|
||||
--AND o.calc_status <> 'CANCELED'
|
||||
--AND o.fs_line = '41010'
|
||||
@ -135,13 +117,13 @@ CREATE MATERIALIZED VIEW rlarp.price_pool_dev AS (
|
||||
,substring(o.version,1,1)
|
||||
,o.chanwide
|
||||
,o.nursery_region
|
||||
,c.greenhouse_region
|
||||
,m.part_group
|
||||
,m.majg
|
||||
,m.assc
|
||||
,i.coltier
|
||||
,'v1:' || rtrim(COALESCE(i.coltier, ''))|| '.' || rtrim(substring(COALESCE(i.branding, ''), 1, 1))|| '.' || rtrim(COALESCE(i.uomp, ''))|| '.' || rtrim(COALESCE(i.suffix, ''))|| '.' || rtrim(COALESCE(i.accs_ps, ''))
|
||||
,_ds.dataseg
|
||||
,o.greenhouse_region
|
||||
,o.partgroup
|
||||
,o.majg
|
||||
,o.assc
|
||||
,o.coltier
|
||||
,o.dataseg
|
||||
,o.v0dataseg
|
||||
,o.oseas
|
||||
HAVING
|
||||
round(sum(o.qty),0) > 0
|
||||
@ -241,5 +223,5 @@ CREATE MATERIALIZED VIEW rlarp.price_pool_dev AS (
|
||||
--LIMIT 1000
|
||||
) WITH DATA;
|
||||
|
||||
create index ppd_gset on rlarp.price_pool_dev using gin (gset);
|
||||
create index ppd_gset on rlarp.price_pool using gin (gset);
|
||||
--END;
|
||||
|
@ -115,7 +115,7 @@ lq AS MATERIALIZED (
|
||||
,seas.*
|
||||
FROM
|
||||
lqg g
|
||||
LEFT OUTER JOIN rlarp.price_pool_dev p ON
|
||||
LEFT OUTER JOIN rlarp.price_pool p ON
|
||||
p.gset @> jsonb_build_object('mold',g.part_group)
|
||||
AND p.gset ? 'cust'
|
||||
AND p.gset ? 'v1ds'
|
||||
|
Loading…
Reference in New Issue
Block a user