update product notion to include color tier
This commit is contained in:
parent
683921dda0
commit
704957a2fa
@ -64,6 +64,7 @@ incr AS (
|
|||||||
,p AS (
|
,p AS (
|
||||||
SELECT
|
SELECT
|
||||||
o.part
|
o.part
|
||||||
|
,o.styc||'.'||o.coltier||substring(o.sizc,1,3) productt
|
||||||
,o.styc||'.'||o.colgrp||substring(o.sizc,1,3) product
|
,o.styc||'.'||o.colgrp||substring(o.sizc,1,3) product
|
||||||
,o.glec
|
,o.glec
|
||||||
,o.styc
|
,o.styc
|
||||||
@ -119,8 +120,7 @@ incr AS (
|
|||||||
,o.shipgrp
|
,o.shipgrp
|
||||||
,o.odate DESC
|
,o.odate DESC
|
||||||
)
|
)
|
||||||
SELECT * FROM p WHERE account ~ 'AMERICAN HORT' and product = 'AZA06000.CBXX' and chgrp = 'W' order by rn ASC
|
--SELECT * FROM p WHERE account ~ 'AMERICAN HORT' and product = 'AZA06000.CBXX' and chgrp = 'W' order by rn ASC
|
||||||
|
|
||||||
------------build global py asp------------------
|
------------build global py asp------------------
|
||||||
,baseline AS (
|
,baseline AS (
|
||||||
SELECT
|
SELECT
|
||||||
@ -137,83 +137,81 @@ SELECT * FROM p WHERE account ~ 'AMERICAN HORT' and product = 'AZA06000.CBXX' an
|
|||||||
,assc
|
,assc
|
||||||
,chgrp
|
,chgrp
|
||||||
)
|
)
|
||||||
SELECT
|
--SELECT
|
||||||
p.product
|
-- p.product
|
||||||
--,p.styc
|
-- --,p.styc
|
||||||
--,p.glec
|
-- --,p.glec
|
||||||
,p.majg
|
-- ,p.majg
|
||||||
,p.assc
|
-- ,p.assc
|
||||||
,p.colgrp
|
-- ,p.colgrp
|
||||||
--,p.coltier
|
-- --,p.coltier
|
||||||
--,p.sizc
|
-- --,p.sizc
|
||||||
--,p.suffix
|
-- --,p.suffix
|
||||||
,p.chgrp
|
-- ,p.chgrp
|
||||||
,p.account
|
-- ,p.account
|
||||||
,p.shipgrp
|
-- ,p.shipgrp
|
||||||
--,bl.py_gasp
|
-- --,bl.py_gasp
|
||||||
,sum(units) FILTER (WHERE oseas = 2020) py_units
|
-- ,sum(units) FILTER (WHERE oseas = 2020) py_units
|
||||||
,sum(units) FILTER (WHERE oseas = 2021) cy_units
|
-- ,sum(units) FILTER (WHERE oseas = 2021) cy_units
|
||||||
,round(sum(val_usd) FILTER (WHERE oseas = 2020)/sum(units) FILTER (WHERE oseas = 2020),5) py_asp
|
-- ,round(sum(val_usd) FILTER (WHERE oseas = 2020)/sum(units) FILTER (WHERE oseas = 2020),5) py_asp
|
||||||
,round(avg(price) FILTER (WHERE rn = 1),5) last_price
|
-- ,round(avg(price) FILTER (WHERE rn = 1),5) last_price
|
||||||
,max(odate) FILTER (WHERE rn = 1) last_order
|
-- ,max(odate) FILTER (WHERE rn = 1) last_order
|
||||||
,i.rate incr_rate
|
-- ,i.rate incr_rate
|
||||||
,CASE p.chgrp
|
-- ,CASE p.chgrp
|
||||||
WHEN 'D' THEN .5
|
-- WHEN 'D' THEN .5
|
||||||
ELSE CASE p.majg
|
-- ELSE CASE p.majg
|
||||||
WHEN '610' THEN .02
|
-- WHEN '610' THEN .02
|
||||||
ElSE CASE p.colgrp
|
-- ElSE CASE p.colgrp
|
||||||
WHEN 'B' THEN .15
|
-- WHEN 'B' THEN .15
|
||||||
WHEN 'C' THEN .20
|
-- WHEN 'C' THEN .20
|
||||||
ELSE 1
|
-- ELSE 1
|
||||||
END
|
-- END
|
||||||
END
|
-- END
|
||||||
END rate
|
-- END rate
|
||||||
--,CASE WHEN sum(val_usd) FILTER (WHERE oseas = 2020) IS NULL
|
-- --,CASE WHEN sum(val_usd) FILTER (WHERE oseas = 2020) IS NULL
|
||||||
-- THEN CASE WHEN sum(units) FILTER (WHERE oseas = 2021) IS NULL
|
-- -- THEN CASE WHEN sum(units) FILTER (WHERE oseas = 2021) IS NULL
|
||||||
-- THEN 'unknown'
|
-- -- THEN 'unknown'
|
||||||
-- ELSE 'new'
|
-- -- ELSE 'new'
|
||||||
-- END
|
-- -- END
|
||||||
-- ELSE CASE WHEN sum(units) FILTER (WHERE oseas = 2021) IS NULL
|
-- -- ELSE CASE WHEN sum(units) FILTER (WHERE oseas = 2021) IS NULL
|
||||||
-- THEN 'lost'
|
-- -- THEN 'lost'
|
||||||
-- ELSE 'repeat'
|
-- -- ELSE 'repeat'
|
||||||
-- END
|
-- -- END
|
||||||
--END flag
|
-- --END flag
|
||||||
FROM
|
--FROM
|
||||||
p
|
-- p
|
||||||
LEFT OUTER JOIN baseline bl ON
|
-- LEFT OUTER JOIN baseline bl ON
|
||||||
bl.product = p.product
|
-- bl.product = p.product
|
||||||
AND bl.majg = p.majg
|
-- AND bl.majg = p.majg
|
||||||
AND bl.assc = p.assc
|
-- AND bl.assc = p.assc
|
||||||
AND bl.chgrp = p.chgrp
|
-- AND bl.chgrp = p.chgrp
|
||||||
LEFT OUTER JOIN incr i ON
|
-- LEFT OUTER JOIN incr i ON
|
||||||
i.majg = p.majg
|
-- i.majg = p.majg
|
||||||
AND i.assc = p.assc
|
-- AND i.assc = p.assc
|
||||||
AND i.coltier = p.coltier
|
-- AND i.coltier = p.coltier
|
||||||
AND p.glec <> '1RE'
|
-- AND p.glec <> '1RE'
|
||||||
WHERE
|
--WHERE
|
||||||
p.account ~ 'AMERICAN HORT' and p.product = 'AZA06000.CBXX' and p.chgrp = 'W'
|
-- p.account ~ 'AMERICAN HORT' and p.product = 'AZA06000.CBXX' and p.chgrp = 'W'
|
||||||
GROUP BY
|
--GROUP BY
|
||||||
p.product
|
-- p.product
|
||||||
--,p.styc
|
-- --,p.styc
|
||||||
--,p.glec
|
-- --,p.glec
|
||||||
,p.majg
|
-- ,p.majg
|
||||||
,p.assc
|
-- ,p.assc
|
||||||
--,p.coltier
|
-- --,p.coltier
|
||||||
,p.colgrp
|
-- ,p.colgrp
|
||||||
--,p.sizc
|
-- --,p.sizc
|
||||||
--,p.suffix
|
-- --,p.suffix
|
||||||
,p.chgrp
|
-- ,p.chgrp
|
||||||
,p.account
|
-- ,p.account
|
||||||
,p.shipgrp
|
-- ,p.shipgrp
|
||||||
--,bl.py_gasp
|
-- --,bl.py_gasp
|
||||||
,i.rate
|
-- ,i.rate
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
----------calculate pricing as it sits in the forecast--------------
|
----------calculate pricing as it sits in the forecast--------------
|
||||||
,poolprice AS (
|
,poolprice AS (
|
||||||
SELECT
|
SELECT
|
||||||
i.stlc||'.'||i.colgrp||substring(i.sizc,1,3) product
|
i.stlc||'.'||i.coltier||substring(i.sizc,1,3) productt
|
||||||
|
,i.stlc||'.'||i.colgrp||substring(i.sizc,1,3) product
|
||||||
,o.quota_rep_descr
|
,o.quota_rep_descr
|
||||||
,substring(majg,1,3) majg
|
,substring(majg,1,3) majg
|
||||||
,substring(chan,1,1) chgrp
|
,substring(chan,1,1) chgrp
|
||||||
@ -236,7 +234,8 @@ WHERE
|
|||||||
--only include baseline stuff---
|
--only include baseline stuff---
|
||||||
AND segm <> 'Retail'
|
AND segm <> 'Retail'
|
||||||
GROUP BY
|
GROUP BY
|
||||||
i.stlc||'.'||i.colgrp||substring(i.sizc,1,3)
|
i.stlc||'.'||i.coltier||substring(i.sizc,1,3)
|
||||||
|
,i.stlc||'.'||i.colgrp||substring(i.sizc,1,3)
|
||||||
,o.quota_rep_descr
|
,o.quota_rep_descr
|
||||||
,substring(majg,1,3)
|
,substring(majg,1,3)
|
||||||
,substring(chan,1,1)
|
,substring(chan,1,1)
|
||||||
@ -250,7 +249,8 @@ HAVING
|
|||||||
----------pivot the pricing out into columns per customer/product--------
|
----------pivot the pricing out into columns per customer/product--------
|
||||||
,pivot AS (
|
,pivot AS (
|
||||||
SELECT
|
SELECT
|
||||||
p.product
|
p.productt
|
||||||
|
,p.product
|
||||||
--,p.styc
|
--,p.styc
|
||||||
--,p.glec
|
--,p.glec
|
||||||
,p.majg
|
,p.majg
|
||||||
@ -266,6 +266,7 @@ SELECT
|
|||||||
,sum(units) FILTER (WHERE oseas = 2020) py_units
|
,sum(units) FILTER (WHERE oseas = 2020) py_units
|
||||||
,sum(units) FILTER (WHERE oseas = 2021) cy_units
|
,sum(units) FILTER (WHERE oseas = 2021) cy_units
|
||||||
,round(sum(val_usd) FILTER (WHERE oseas = 2020)/sum(units) FILTER (WHERE oseas = 2020),5) py_asp
|
,round(sum(val_usd) FILTER (WHERE oseas = 2020)/sum(units) FILTER (WHERE oseas = 2020),5) py_asp
|
||||||
|
,round(sum(val_usd) FILTER (WHERE oseas = 2021)/sum(units) FILTER (WHERE oseas = 2021),5) cy_asp
|
||||||
,round(avg(price) FILTER (WHERE rn = 1),5) last_price
|
,round(avg(price) FILTER (WHERE rn = 1),5) last_price
|
||||||
,max(odate) FILTER (WHERE rn = 1) last_order
|
,max(odate) FILTER (WHERE rn = 1) last_order
|
||||||
,CASE p.chgrp
|
,CASE p.chgrp
|
||||||
@ -302,7 +303,8 @@ FROM
|
|||||||
AND i.coltier = p.coltier
|
AND i.coltier = p.coltier
|
||||||
AND p.glec <> '1RE'
|
AND p.glec <> '1RE'
|
||||||
GROUP BY
|
GROUP BY
|
||||||
p.product
|
p.productt
|
||||||
|
,p.product
|
||||||
--,p.styc
|
--,p.styc
|
||||||
--,p.glec
|
--,p.glec
|
||||||
,p.majg
|
,p.majg
|
||||||
@ -317,40 +319,46 @@ GROUP BY
|
|||||||
,bl.py_gasp
|
,bl.py_gasp
|
||||||
,i.rate
|
,i.rate
|
||||||
)
|
)
|
||||||
,test_unique AS (
|
--,test_unique AS (
|
||||||
SELECT
|
--SELECT
|
||||||
p.*
|
-- p.*
|
||||||
,count(*) OVER (partition by product, chgrp, account, shipgrp) cnt
|
-- ,count(*) OVER (partition by productt, majg, chgrp, account, shipgrp) cnt
|
||||||
FROM
|
--FROM
|
||||||
pivot p
|
-- pivot p
|
||||||
)
|
|
||||||
SELECT * FROM test_unique where cnt > 1
|
|
||||||
--------------join forecast price-------------------
|
|
||||||
--,fcp AS (
|
|
||||||
-- SELECT
|
|
||||||
-- pp.product
|
|
||||||
-- ,pp.quota_rep_descr
|
|
||||||
-- ,pp.order_season
|
|
||||||
-- ,pp.billto_group
|
|
||||||
-- ,pp.shipto_group
|
|
||||||
-- ,p.py_gasp
|
|
||||||
-- ,p.cy_units
|
|
||||||
-- ,p.py_asp
|
|
||||||
-- ,p.last_price
|
|
||||||
-- ,p.last_order
|
|
||||||
-- ,p.rate
|
|
||||||
-- ,p.flag
|
|
||||||
-- ,pp.fc_units
|
|
||||||
-- ,pp.fc_price
|
|
||||||
-- ,pp.iters
|
|
||||||
-- FROM
|
|
||||||
-- poolprice pp
|
|
||||||
-- LEFT OUTER JOIN pivot p ON
|
|
||||||
-- pp.product = p.product
|
|
||||||
-- AND pp.billto_group = p.account
|
|
||||||
-- AND pp.shipto_group = p.shipgrp
|
|
||||||
--)
|
--)
|
||||||
--SELECT * FROM fcp limit 100
|
--SELECT * FROM test_unique where cnt > 1
|
||||||
|
--SELECT * FROM pivot LIMIT 1000
|
||||||
|
--------------join forecast price-------------------
|
||||||
|
,fcp AS (
|
||||||
|
SELECT
|
||||||
|
pp.productt
|
||||||
|
,pp.product
|
||||||
|
,pp.majg
|
||||||
|
,pp.quota_rep_descr
|
||||||
|
,pp.order_season
|
||||||
|
,pp.billto_group
|
||||||
|
,pp.shipto_group
|
||||||
|
,pp.fc_units
|
||||||
|
,pp.fc_price
|
||||||
|
,pp.iters
|
||||||
|
,p.py_gasp
|
||||||
|
,p.cy_units
|
||||||
|
,p.py_asp
|
||||||
|
,p.last_price
|
||||||
|
,p.last_order
|
||||||
|
,p.rate
|
||||||
|
--need to link in targets pricing and price list for cap purposes---------
|
||||||
|
,COALESCE(py_asp,py_gasp) * (1 + rate) fc_price
|
||||||
|
FROM
|
||||||
|
poolprice pp
|
||||||
|
LEFT OUTER JOIN pivot p ON
|
||||||
|
pp.productt = p.productt
|
||||||
|
AND pp.majg = p.majg
|
||||||
|
AND pp.chgrp = p.chgrp
|
||||||
|
AND pp.billto_group = p.account
|
||||||
|
AND pp.shipto_group = p.shipgrp
|
||||||
|
)
|
||||||
|
SELECT * FROM fcp limit 100
|
||||||
----------------create the new price-----------------
|
----------------create the new price-----------------
|
||||||
--,adj AS (
|
--,adj AS (
|
||||||
--SELECT
|
--SELECT
|
||||||
|
Loading…
Reference in New Issue
Block a user