Last active
October 2, 2023 19:22
-
-
Save thmsobrmlr/a1ee8f0257ac0b226cf5a55e6eda9c36 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT uuid, | |
event, | |
properties, | |
timestamp, | |
team_id, | |
distinct_id, | |
elements_chain, | |
created_at | |
FROM events | |
WHERE team_id = 2 | |
AND timestamp > '2023-10-01 19:14:05.127164' | |
AND timestamp < '2023-10-02 19:14:10.127183' | |
AND ( | |
( | |
event = 'billing free trial activated' | |
AND ( | |
distinct_id IN ( | |
SELECT distinct_id | |
FROM ( | |
SELECT distinct_id, | |
argMax(person_id, version) as person_id | |
FROM person_distinct_id2 | |
WHERE team_id = 2 | |
GROUP BY distinct_id | |
HAVING argMax(is_deleted, version) = 0 | |
) | |
WHERE person_id IN ( | |
SELECT id | |
FROM ( | |
SELECT id, | |
argMax(properties, person._timestamp) as properties, | |
max(is_deleted) as is_deleted | |
FROM person | |
WHERE team_id = 2 | |
GROUP BY id | |
HAVING is_deleted = 0 | |
) | |
WHERE has( | |
['true'], | |
replaceRegexpAll( | |
JSONExtractRaw(properties, 'is_organization_first_user'), | |
'^"|"$', | |
'' | |
) | |
) | |
) | |
) | |
) | |
) | |
) | |
ORDER BY timestamp DESC | |
LIMIT 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT tuple( | |
events.uuid, | |
events.event, | |
events.properties, | |
toTimeZone(events.timestamp, 'US/Pacific'), | |
events.team_id, | |
events.distinct_id, | |
events.elements_chain, | |
toTimeZone(events.created_at, 'US/Pacific') | |
), | |
events.distinct_id | |
FROM events | |
WHERE | |
and( | |
equals(events.team_id, 2), | |
and( | |
equals(events.event, 'billing free trial activated'), | |
ifNull( | |
equals( | |
ifNull( | |
equals( | |
replaceRegexpAll( | |
nullIf( | |
nullIf( | |
JSONExtractRaw( | |
events.person_properties, | |
'is_organization_first_user' | |
), | |
'' | |
), | |
'null' | |
), | |
'^"|"$', | |
'' | |
), | |
'true' | |
), | |
0 | |
), | |
true | |
), | |
0 | |
) | |
), | |
ifNull( | |
less( | |
toTimeZone(events.timestamp, 'US/Pacific'), | |
toDateTime64('2023-10-02 12:13:07.059946', 6, 'US/Pacific') | |
), | |
0 | |
) | |
) | |
ORDER BY toTimeZone(events.timestamp, 'US/Pacific') DESC | |
LIMIT 4 OFFSET 0 SETTINGS readonly = 2, | |
max_execution_time = 60, | |
allow_experimental_object_type = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment