K
то есть данные рандомные
сча поправлю набор
Size: a a a
K
K
AP
AP
K
D
K
K
D
K
D
AP
K
D
select evtType, min(evttime), max(evttime) from (
select (arrayJoin([(1,'evt1'),(2,'evt1'),(3,'evt2'), (4,'evt2')]) as arr).1 as evttime, arr.2 as evtType
) group by evtType
AP
SELECT
pair[1] AS first_action,
pair[2] AS second_action,
timestamp[1] AS start,
timestamp[2] AS end
FROM
(
SELECT
arraySplit((a,i)-> i % 2 = 1, groupArray(action) as actions,arrayMap(a->if(a='s',1,2), actions) as ind) as pairs,
arraySplit((t,i)-> i % 2 = 1, groupArray(time),ind) as timestamps
FROM
(
SELECT
now() + t AS time,
action
FROM system.one
ARRAY JOIN
[1,2,3,4,5,6,7,8,9,10] AS t,
['s','1','7','e','8','s','6','e','s','e'] AS action
ORDER BY time
)
WHERE action in ('s','e')
)
ARRAY JOIN
pairs AS pair,
timestamps AS timestamp
AP
SELECT
now() + t AS time,
action
FROM system.one
ARRAY JOIN
[1,2,3,4,5,6,7,8,9,10] AS t,
['s','1','7','e','8','s','6','e','s','e'] AS action
ORDER BY time
AP
DC
K
AP