I want to do retention/event analytics based on buried point data that are stored in ClickHouse. Let's say I have two types of events: app_launch (buried_point_id=1) and user_register (buried_point_id=2). I want to understand: Within the 1-day time window, how many users register after launching the app. See sample buried point data below:
buried_point_id | happened_at | user_id |
---|---|---|
1 | 1613923200 | 123 |
1 | 1614009600 | 345 |
2 | 1613966400 | 123 |
2 | 1614009600 | 234 |
2 | 1614182400 | 345 |
Here's the query I want to run:
SELECT COUNT (DISTINCT t1.user_id), COUNT (DISTINCT t2.user_id)
FROM
(SELECT user_id,
happened_at
FROM buried_points
WHERE buried_point_id = 1
AND happened_at >= 1613923200
AND happened_at <= 1614182400
AND ) AS t1
ASOF LEFT JOIN
(SELECT user_id,
happened_at
FROM buried_points
WHERE buried_point_id = 2
AND happened_at >= 1613923200
AND happened_at <= 1614182400) AS t2
ON t1.user_id = t2.user_id
AND t1.happened_at < t2.happened_at
AND t2.happened_at - t1.happened_at < 86400;
This is the expected query result:
2 (123,345), 1 (123)
However, according to ClickHouse docs, only 1 inequality can be supported:
You can use any number of equality conditions and exactly one closest match condition. For example, SELECT count() FROM table_1 ASOF LEFT JOIN table_2 ON table_1.a == table_2.b AND table_2.t <= table_1.t. Conditions supported for the closest match: >, >=, <, <=.
However I need 2 inequalities to do my work - Is there a work around to this problem?