price_api/sql/live_quotes_review.pg.sql

71 lines
2.1 KiB
MySQL
Raw Permalink Normal View History

2024-03-14 14:57:35 -04:00
set work_mem TO '4GB';
2024-04-25 11:09:15 -04:00
DROP VIEW IF EXISTS rlarp.live_quotes_review;
2024-04-05 09:24:18 -04:00
CREATE VIEW rlarp.live_quotes_review AS
2023-11-20 13:53:43 -05:00
WITH
lq AS MATERIALIZED (
SELECT
lq.*
,substring(lq.part,1,8) mold
FROM
pricequote.live_quotes lq
)
,lqg AS (
SELECT
lq.*
2023-11-20 15:46:59 -05:00
,pricing->'product'->>'mold' part_group
2024-12-13 09:46:50 -05:00
-- ,substring(pricing->'customer'->>'chan',1,1) qchan
2023-11-21 10:00:30 -05:00
,pricing->'customer'->>'cust' qcust
2023-11-20 15:46:59 -05:00
,pricing->'product'->>'itemrel' item_fit
,(pricing->'product'->>'pltq')::numeric pltq
2023-11-20 13:53:43 -05:00
,(pricing->'guidance'->'finalPrice'->>'Price')::numeric guidance
,pricing->'guidance'->'finalPrice'->>'Reason' reason
2024-04-05 09:24:18 -04:00
,(pricing->'product'->>'cstd_usd_ina')::numeric cstd_usd
2023-11-29 08:16:26 -05:00
,(pricing->'product'->>'fstd_usd_ina')::numeric fstd_usd
2023-11-20 15:56:18 -05:00
,(pricing->'guidance'->>'ltp')::numeric ltp
,(pricing->'guidance'->>'optimization')::numeric optimization
,(pricing->'guidance'->>'inflationFactor')::numeric inflation
2023-11-20 13:53:43 -05:00
,jsonb_pretty(pricing) pricing
FROM
lq
LEFT JOIN LATERAL rlarp.guidance_r1(
2024-12-13 09:23:00 -05:00
rlarp.get_guidance_dseg(lq.billto,lq.shipto,substring(lq.part,1,8),lq.v1ds,lq.units_each,2025)
2023-11-20 13:53:43 -05:00
) pricing ON TRUE
WHERE
lq.qstat ~ 'Submitted'
)
,hist AS (
SELECT
g.*
,gset.chan
--,gset.mold moldh
,gset.v1ds v1dsh
,gset.cust
,gset.vers
,je.k
,seas.*
FROM
lqg g
LEFT OUTER JOIN rlarp.price_pool_dev p ON
p.gset @> jsonb_build_object('mold',g.part_group)
AND p.gset ? 'cust'
AND p.gset ? 'v1ds'
LEFT JOIN LATERAL jsonb_to_record(p.gset) AS gset(
chan text
,mold text
,v1ds text
,v0ds text
,cust text
,vers text
--,nurs text
--,ghse text
) ON TRUE
LEFT JOIN LATERAL jsonb_each(p.season) je(k,v) on true
LEFT JOIN Lateral jsonb_to_record(je.v) as seas(
units numeric
,sales_usd numeric
,price_usd numeric
) ON TRUE
)
SELECT * FROM hist