price_api/sql/spread.pg.sql

19 lines
621 B
MySQL
Raw Normal View History

2023-11-08 12:42:46 -05:00
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..')