adjust history function
This commit is contained in:
parent
970968f980
commit
5234516dee
@ -1,5 +1,5 @@
|
||||
WITH
|
||||
sel AS (select 'v1:L..PLT..' _v1ds, 'GRIFFIN' _cust, 'ULH12000' _mold, 'W' _chan)
|
||||
sel AS (select 'v1:T..PLT..' _v1ds, 'KAWAHARA NURSERY' _cust, 'AZE10001' _mold, 'D' _chan)
|
||||
,sort AS (
|
||||
SELECT
|
||||
p.agglevel
|
||||
@ -53,6 +53,19 @@ sel AS (select 'v1:L..PLT..' _v1ds, 'GRIFFIN' _cust, 'ULH12000' _mold, 'W' _chan
|
||||
source ASC
|
||||
,rn ASC
|
||||
)
|
||||
,rel AS (
|
||||
SELECT * FROM (values
|
||||
('customer exact' ,1)
|
||||
,('customer v0ds other',7)
|
||||
,('customer v0ds vol' ,3)
|
||||
,('customer v1ds other',6)
|
||||
,('customer v1ds vol' ,2) --this will always sort to the top, v0ds will never sort to the top. you will always be getting the highest volume base price
|
||||
,('market exact' ,4)
|
||||
,('market v0ds other' ,9)
|
||||
,('market v0ds vol' ,5)
|
||||
,('market v1ds other' ,8)
|
||||
) x (flag,prefer)
|
||||
)
|
||||
,flag AS (
|
||||
SELECT
|
||||
--agglevel
|
||||
@ -84,6 +97,7 @@ SELECT
|
||||
,cust
|
||||
,vers
|
||||
,rn
|
||||
,row_number() OVER (PARTITION BY source ORDER BY rel.prefer ASC) rnk
|
||||
,avgunits
|
||||
,avgordcount
|
||||
,avgcustcount
|
||||
@ -97,19 +111,25 @@ SELECT
|
||||
,season
|
||||
FROM
|
||||
sort
|
||||
)
|
||||
,rel AS (
|
||||
SELECT * FROM (values
|
||||
('customer exact' ,1)
|
||||
,('customer v0ds other',7)
|
||||
,('customer v0ds vol' ,3)
|
||||
,('customer v1ds other',6)
|
||||
,('customer v1ds vol' ,2) --this will always sort to the top, v0ds will never sort to the top. you will always be getting the highest volume base price
|
||||
,('market exact' ,4)
|
||||
,('market v0ds other' ,9)
|
||||
,('market v0ds vol' ,5)
|
||||
,('market v1ds other' ,8)
|
||||
) x (flag,prefer)
|
||||
LEFT OUTER JOIN rel ON
|
||||
rel.flag = CASE source
|
||||
WHEN 'cust' THEN
|
||||
CASE WHEN v1ds IS NOT NULL THEN
|
||||
CASE WHEN v1ds_match THEN 'customer exact' ELSE
|
||||
CASE WHEN rn = 1 THEN 'customer v1ds vol' ELSE 'customer v1ds other' END
|
||||
END
|
||||
ELSE
|
||||
CASE WHEN rn = 1 THEN 'customer v0ds vol' ELSE 'customer v0ds other' END
|
||||
END
|
||||
ELSE
|
||||
CASE WHEN v1ds IS NOT NULL THEN
|
||||
CASE WHEN v1ds_match THEN 'market exact' ELSE
|
||||
CASE WHEN rn = 1 THEN 'market v1ds vol' ELSE 'market v1ds other' END
|
||||
END
|
||||
ELSE
|
||||
CASE WHEN rn = 1 THEN 'market v0ds vol' ELSE 'market v0ds other' END
|
||||
END
|
||||
END
|
||||
)
|
||||
,rel_sort AS (
|
||||
SELECT
|
||||
@ -133,17 +153,15 @@ FROM
|
||||
,'last_season' ,last_season
|
||||
,'last_price' ,last_price
|
||||
,'ds' ,COALESCE(v1ds,v0ds)
|
||||
,'rank' ,row_number() OVER (PARTITION BY flag.source ORDER BY rel.prefer ASC)
|
||||
,'rank' ,rnk
|
||||
,'pricinghistory' ,season
|
||||
)
|
||||
)
|
||||
) doc
|
||||
,row_number() OVER (PARTITION BY flag.source ORDER BY rel.prefer ASC) rnk
|
||||
,rnk
|
||||
,season
|
||||
FROM
|
||||
flag
|
||||
LEFT OUTER JOIN rel ON
|
||||
rel.flag = flag.relevance
|
||||
WHERE
|
||||
relevance ~ 'vol|exact'
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user