From 31039876971b58fe734d6ae941a68dba69d4d8ad Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Wed, 8 Nov 2023 12:42:46 -0500 Subject: [PATCH] vault backup: 2023-11-08 12:42:46 --- sql/gethist_table.pg.sql | 45 ++++++++++++++++++++++++++++++++++++++++ sql/spread.pg.sql | 18 ++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 sql/gethist_table.pg.sql create mode 100644 sql/spread.pg.sql diff --git a/sql/gethist_table.pg.sql b/sql/gethist_table.pg.sql new file mode 100644 index 0000000..653c2bc --- /dev/null +++ b/sql/gethist_table.pg.sql @@ -0,0 +1,45 @@ +WITH +getj AS ( + SELECT + ( + SELECT + jsonb_build_object('mold',JSON_AGG(DISTINCT stlc)) doc + FROM + "CMS.CUSLG".itemm + WHERE + item ~ 'TUH10000A10B04' + ) || + ( + SELECT + jsonb_build_object('cust',JSONB_AGG(DISTINCT c.dba)) + FROM + rlarp.cust c + WHERE + c.dba ~ 'DIAMOND R' + ) doc +) +,agg AS ( + SELECT + gset + ,(SELECT string_agg(ae.v,'.') FROM jsonb_array_elements_text(p.agglevel) ae(v)) agglvl + ,season + --,(select doc from getj) gdoc + FROM + rlarp.price_pool_dev p + WHERE + --gut the exact mold and actuals only + gset @> jsonb_build_object( + 'mold',(SELECT doc->'mold'->>0 FROM getj), + 'vers','A' + ) + --pull either the exact customer or no customer + AND ( + gset @> jsonb_build_object( + 'cust',(SELECT doc->'cust'->>0 FROM getj) + ) + OR NOT gset ? 'cust' + ) + ORDER BY + agglevel ASC +) +SELECT * FROM agg diff --git a/sql/spread.pg.sql b/sql/spread.pg.sql new file mode 100644 index 0000000..5a470f0 --- /dev/null +++ b/sql/spread.pg.sql @@ -0,0 +1,18 @@ +WITH +--targte spreads-- +ts AS ( + SELECT + t.* + --, round(target_price/min(target_price) over (partition by mold, chan, season),5) spread + , target_price/min(target_price) over (partition by mold, chan, season) spread + FROM + pricequote.market_setavgprice t + WHERE + mold = 'FHR14000' + and season = 2024 + and chan = 'DIRECT' + and data_segment like 'v1%' + ORDER BY + target_price ASC +) +SELECT mold, chan, season, data_segment, spread, max(spread) over (), min(spread) OVER () spread FROM ts WHERE data_segment IN ('v1:B..SLV..','v1:S..SLV..')