include pricing and colors in final query
This commit is contained in:
parent
690b325e78
commit
fcdb134b76
@ -1,3 +1,4 @@
|
|||||||
|
--EXPLAIN (ANALYZE, BUFFERS)
|
||||||
WITH
|
WITH
|
||||||
pc AS materialized (
|
pc AS materialized (
|
||||||
SELECT
|
SELECT
|
||||||
@ -31,22 +32,23 @@ SELECT
|
|||||||
,pc.branding
|
,pc.branding
|
||||||
,pc.ACCS
|
,pc.ACCS
|
||||||
,pc.SUFFIX
|
,pc.SUFFIX
|
||||||
,string_agg( DISTINCT ltrim(rtrim(i.COLC)),', ') clist
|
,string_agg( DISTINCT ltrim(rtrim(i.COLC)),', ') tclist
|
||||||
----price 1 -----------------
|
,jsonb_agg( DISTINCT ltrim(rtrim(i.COLC))) clist
|
||||||
,pc.PCKG1
|
------price 1 -----------------
|
||||||
,pc.VOLL1
|
--,pc.PCKG1
|
||||||
,pc.VOL1_UOM
|
--,pc.VOLL1
|
||||||
,pc.VOL1_PRICE
|
--,pc.VOL1_UOM
|
||||||
----price 2 -----------------
|
--,pc.VOL1_PRICE
|
||||||
,pc.PCKG2
|
------price 2 -----------------
|
||||||
,pc.VOLl2
|
--,pc.PCKG2
|
||||||
,pc.VOL2_UOM
|
--,pc.VOLl2
|
||||||
,pc.VOL2_PRICE
|
--,pc.VOL2_UOM
|
||||||
----price 3 -----------------
|
--,pc.VOL2_PRICE
|
||||||
,pc.PCKG1
|
------price 3 -----------------
|
||||||
,pc.VOLL3
|
--,pc.PCKG1
|
||||||
,pc.VOL3_UOM
|
--,pc.VOLL3
|
||||||
,pc.VOL3_PRICE
|
--,pc.VOL3_UOM
|
||||||
|
--,pc.VOL3_PRICE
|
||||||
FROM
|
FROM
|
||||||
pc
|
pc
|
||||||
LEFT OUTER JOIN RLARP.ITEMMv i ON
|
LEFT OUTER JOIN RLARP.ITEMMv i ON
|
||||||
@ -91,6 +93,8 @@ GROUP BY
|
|||||||
,1 col
|
,1 col
|
||||||
,pc.pckg1 pckg
|
,pc.pckg1 pckg
|
||||||
,pc.vol1_uom vol_uom
|
,pc.vol1_uom vol_uom
|
||||||
|
,pc.voll1 vol_qty
|
||||||
|
,pc.vol1_price price
|
||||||
FROM
|
FROM
|
||||||
pc
|
pc
|
||||||
UNION
|
UNION
|
||||||
@ -103,6 +107,8 @@ GROUP BY
|
|||||||
,2 col
|
,2 col
|
||||||
,pc.pckg2 pckg
|
,pc.pckg2 pckg
|
||||||
,pc.vol2_uom vol_uom
|
,pc.vol2_uom vol_uom
|
||||||
|
,pc.voll2 vol_qty
|
||||||
|
,pc.vol2_price price
|
||||||
FROM
|
FROM
|
||||||
pc
|
pc
|
||||||
UNION
|
UNION
|
||||||
@ -115,6 +121,8 @@ GROUP BY
|
|||||||
,3 col
|
,3 col
|
||||||
,pc.pckg3 pckg
|
,pc.pckg3 pckg
|
||||||
,pc.vol3_uom vol_uom
|
,pc.vol3_uom vol_uom
|
||||||
|
,pc.voll3 vol_qty
|
||||||
|
,pc.vol3_price price
|
||||||
FROM
|
FROM
|
||||||
pc
|
pc
|
||||||
)
|
)
|
||||||
@ -130,8 +138,25 @@ SELECT
|
|||||||
--retain this column to re-pivot back to original format
|
--retain this column to re-pivot back to original format
|
||||||
,up.col
|
,up.col
|
||||||
,up.vol_uom
|
,up.vol_uom
|
||||||
|
,up.voL_qty
|
||||||
|
,up.price
|
||||||
,row_number() OVER (PARTITION BY up.stlc, up.coltier, up.branding, up.accs, up.suffix, up.pckg, up.col, up.vol_uom ORDER BY item DESC) seq
|
,row_number() OVER (PARTITION BY up.stlc, up.coltier, up.branding, up.accs, up.suffix, up.pckg, up.col, up.vol_uom ORDER BY item DESC) seq
|
||||||
,item
|
,item
|
||||||
|
--subquery option is not performant at all
|
||||||
|
--,(
|
||||||
|
-- SELECT
|
||||||
|
-- item
|
||||||
|
-- FROM
|
||||||
|
-- rlarp.itemmv v
|
||||||
|
-- WHERE
|
||||||
|
-- v.stlc = up.stlc
|
||||||
|
-- AND v.branding = up.branding
|
||||||
|
-- AND v.accs = up.accs
|
||||||
|
-- AND v.suffix = up.suffix
|
||||||
|
-- AND v.uomp ? up.pckg
|
||||||
|
-- AND v.aplnt <> 'I'
|
||||||
|
-- LIMIT 1
|
||||||
|
--) item_subq
|
||||||
FROM
|
FROM
|
||||||
unpivot up
|
unpivot up
|
||||||
LEFT OUTER JOIN RLARP.ITEMMv i ON
|
LEFT OUTER JOIN RLARP.ITEMMv i ON
|
||||||
@ -175,13 +200,16 @@ FROM
|
|||||||
SELECT
|
SELECT
|
||||||
i.*
|
i.*
|
||||||
,c.*
|
,c.*
|
||||||
|
,l.clist
|
||||||
FROM
|
FROM
|
||||||
items_init i
|
items_init i
|
||||||
LEFT OUTER JOIN conversion c ON
|
LEFT OUTER JOIN conversion c ON
|
||||||
c.p = i.item
|
c.p = i.item
|
||||||
|
AND c.f = i.vol_uom
|
||||||
|
NATURAL JOIN colors l
|
||||||
WHERE
|
WHERE
|
||||||
i.seq = 1
|
i.seq = 1
|
||||||
ORDER BY
|
ORDER BY
|
||||||
stlc
|
i.stlc
|
||||||
,coltier
|
,i.coltier
|
||||||
,col
|
,i.col
|
||||||
|
Loading…
Reference in New Issue
Block a user