Я бы хотел получить разрешение на день. Похоже, это работает хорошо.
SELECT
contract_id
, the_minute
, open
, high
, low
, close
FROM
(
SELECT
contract_id
, TO_CHAR(ts, 'YYMMDDHH24MI') AS the_minute
, MIN(price) OVER w AS low
, MAX(price) OVER w AS high
, LAST_VALUE(price) OVER w AS open -- Note the window is in reverse (first value comes last)
, FIRST_VALUE(price) OVER w AS close -- Note the window is in reverse (last value comes first)
, RANK() OVER w AS the_rank
FROM fill
WINDOW w AS (PARTITION BY contract_id, TO_CHAR(ts, 'YYMMDDHH24MI') ORDER BY fill_id DESC)
) AS inr
WHERE the_rank = 1
ORDER BY 1, 2;
Спасибо, Скотт. Ваш ответ помог мне найти следующее решение.