Pevný počet řádků můžete agregovat pomocí row_number()
a aritmetika:
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);
Toto používá "hack" k získání open
a close
-- pomocí polí.