Hi there,
given CREATE TABLE Actions (ID, UserID, ActionDate, ActionType, ActionParameter), how would you count the number of actions of type 2 happened after the action of type 1 grouped by ActionParameter?
In Vertica, we're using the following query:
select ActionParameter, sum(num_action2) CountAction2 from (
select
action1.id, min(ActionParameter) ActionParameter, ifnull(count(
action2.id), 0) num_action2
from Actions action1
left outer join Actions action2 on action2.ActionType=2 and action1.UserID = action2.UserID and action2.ActionDate > action1.ActionDate
where action1.ActionType=1
and not exists (select 1 from Actions z where z.ActionType=1 and z.UserID = action1.UserID
and z.ActionDate > action1.ActionDate and z.ActionDate < action2.ActionDate)
group by
action1.id) k
group by ActionParameter
order by ActionParameter;
We cannot translate this query to Clickhouse trivially, because correlated subqueries are not supported.
The goal of the query is to study the influence of ActionParameter values of action of type 1 to the number of following actions of type 2.
Thanks,
Maxim