I have the time-series data from the similar hosts that stored in ClickHouse table in the next structure:
event_type | event_day ------------|--------------------- type_1 | 2017-11-09 20:11:28 type_1 | 2017-11-09 20:11:25 type_2 | 2017-11-09 20:11:23 type_2 | 2017-11-09 20:11:21
Each row in the table means the presence of a value 1 for event_type on the datetime. To quickly assess the situation I need to indicate the sum (total) + the last seven values (pulse), like this:
event_type | day | total | pulse ------------|------------|-------|----------------------------- type_1 | 2017-11-09 | 876 | 12,9,23,67,5,34,10 type_2 | 2017-11-09 | 11865 | 267,120,234,425,102,230,150
I tried to get it with one request in the following way, but it failed - the pulse consists of the same values:
with
arrayMap(x -> today() - 7 + x, range(7)) as week_range,
arrayMap(x -> count(event_type), week_range) as pulse
select
event_type,
toDate(event_date) as day,
count() as total,
pulse
from database.table
group by day, event_type
event_type | day | total | pulse ------------|------------|-------|------------------------------------------- type_1 | 2017-11-09 | 876 | 876,876,876,876,876,876,876 type_2 | 2017-11-09 | 11865 | 11865,11865,11865,11865,11865,11865,11865
Please point out where is my mistake and how to get desired?