From da8e1353f31149cae43885d09675d07d3dd55aa3 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Thu, 22 Apr 2021 17:46:56 -0400 Subject: [PATCH] notes on regional pricing and link in target pricing --- offline/last_price.sql | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/offline/last_price.sql b/offline/last_price.sql index 3665d31..d9b2d2d 100644 --- a/offline/last_price.sql +++ b/offline/last_price.sql @@ -60,6 +60,23 @@ incr AS ( ('610','','W',0.02) ) x(MAJG,ASSC,COLTIER,RATE) ) +,chx AS ( + SELECT * FROM ( VALUES + ('DIRECT','DIR','Direct'), + ('DISTRIB DROP SHIP','DRP','Drop'), + ('DISTRIBUTOR','WHS','Warehouse') + ) x(xchan, chan, tchan) +) +,ds AS ( + SELECT * FROM ( VALUES + ('B','X','BASE','Base',''), + ('B','L','BASE LABELED','Base','L'), + ('B','P','BASE PRINTED','Base','P'), + ('C','X','COLOR','Color',''), + ('C','L','COLOR LABELED','Color','L'), + ('C','P','COLOR PRINTED','Color','P') + ) x(colgrp, brand, dataseg, tcol, tbrand) +) ------------carve out pricing baseline data-------------------- ,p AS ( SELECT @@ -75,6 +92,7 @@ incr AS ( ,o.sizc ,i.suffix ,substring(o.chan,1,1) chgrp + ,o.chan ,o.account ,o.shipgrp ,o.fb_qty units @@ -280,6 +298,7 @@ SELECT END END END rate + ,ms.avg_price target --,CASE WHEN sum(val_usd) FILTER (WHERE oseas = 2020) IS NULL -- THEN CASE WHEN sum(units) FILTER (WHERE oseas = 2021) IS NULL -- THEN 'unknown' @@ -302,6 +321,19 @@ FROM AND i.assc = p.assc AND i.coltier = p.coltier AND p.glec <> '1RE' + -----convert to target price channels--------- + LEFT OUTER JOIN chx ON + chx.chan = p.chan + -----convert to target price product level---- + LEFT OUTER JOIN ds ON + ds.colgrp = p.colgrp + AND ds.brand = substring(p.sizc,3,1) + LEFT OUTER JOIN pricequote.market_setavgprice ms ON + ms.mold = substring(p.product,1,8) + AND ms.chan = chx.xchan + AND ms.data_segment = ds.dataseg + AND ms.season = '2021' + AND ms.region = 'ALL' GROUP BY p.productt ,p.product @@ -317,6 +349,7 @@ GROUP BY ,p.account ,p.shipgrp ,bl.py_gasp + ,ms.avg_price ,i.rate ) --,test_unique AS ( @@ -346,8 +379,10 @@ GROUP BY ,p.py_asp ,p.last_price ,p.last_order + ,p.target ,p.rate --need to link in targets pricing and price list for cap purposes--------- + --also need to link regional price lists so we don't blow past those------ ,COALESCE(py_asp,py_gasp) * (1 + rate) fc_price FROM poolprice pp