Vous pouvez agréger un nombre fixe de lignes en utilisant row_number()
et arithmétique :
select min(date),
(array_agg(bid order by seqnum asc))[1] as open,
(array_agg(bid order by seqnum desc))[1] as close,
min(bid) as min_bid, max(bid) as max_bid
from (select t.*, row_number() over (order by date) as seqnum
from ticks t
) t
group by floor((seqnum - 1) / 500);
Cela utilise "hack" pour obtenir le open
et close
-- en utilisant des tableaux.