diff --git a/ee/clickhouse/sql/funnels/funnel.py b/ee/clickhouse/sql/funnels/funnel.py index 7201a807075..6f467d76edc 100644 --- a/ee/clickhouse/sql/funnels/funnel.py +++ b/ee/clickhouse/sql/funnels/funnel.py @@ -22,3 +22,32 @@ GROUP BY max_step {top_level_groupby} ORDER BY max_step {top_level_groupby} ASC ; """ + +FUNNEL_PERSONS_SQL = """ +SELECT max_step {top_level_groupby}, count(1) as cnt, id +FROM +( + SELECT + pid.person_id as id, + {extra_select} + windowFunnel({within_time})(toUInt64(toUnixTimestamp64Micro(timestamp)), + {steps} + ) as max_step + FROM + events + JOIN ( + SELECT person_id, distinct_id FROM ({latest_distinct_id_sql}) WHERE team_id = %(team_id)s + ) as pid + ON pid.distinct_id = events.distinct_id + WHERE + team_id = %(team_id)s {filters} {parsed_date_from} {parsed_date_to} + AND event IN %(events)s + GROUP BY pid.person_id {extra_groupby} +) +WHERE max_step = {current_step} +GROUP BY max_step, id {top_level_groupby} +ORDER BY max_step {top_level_groupby} ASC +limit 50 +offset {offset} +; +"""