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