ar[1].2 as min_players
, ar[1].3 as min_perks
, ar[-1].1 as max_date
, ar[-1].2 as max_players
, ar[-1].3 as max_perks
from
(
select
groupArray(tuple(date, players, perks)) as ar
from guids
where guid_id = 1
and date between toDate(100) and toDate(200)
order by date
)
create table XX (A Int64, B DateTime, V Int64) Engine=MergeTree Order by (B); insert into XX select number / 1000, toDateTime(number/100), number from numbers(100000000); select (select * from XX where A >= 100 order by B desc limit 1) a, (select * from XX where A >= 100 order by B limit 1) b 1 rows in set. Elapsed: 0.032 sec. select ar[1].1 as min_date , ar[1].2 as min_players , ar[1].3 as min_perks , ar[-1].1 as max_date , ar[-1].2 as max_players , ar[-1].3 as max_perks from ( select groupArray(tuple(*)) as ar from XX where A >= 100 group by B ) limit 1 1 rows in set. Elapsed: 0.605 sec. Processed 100.00 million rows, 2.00 GB (165.27 million rows/s., 3.31 GB/s.)
Обсуждают сегодня