Created
November 26, 2024 20:31
-
-
Save robisatthefunction/3e59487c26abd38403eeeeae91e10886 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
WITH events_with_experiment_in_array AS ( | |
SELECT visitor_id, | |
revenue, | |
experiments | |
FROM events | |
WHERE account = '4268742351' | |
AND event = 'seat_revenue' | |
AND cardinality(filter(experiments, e -> e.experiment_id = '25565530461')) > 0 | |
), events_with_experiment_column AS ( | |
SELECT visitor_id, | |
revenue, | |
element_at(filter(experiments, e -> e.experiment_id = '25565530461'), 1) AS "experiment" | |
FROM events_with_experiment_in_array | |
), events_with_all_columns AS ( | |
SELECT visitor_id, | |
revenue, | |
experiment.experiment_id, | |
experiment.variation_id | |
FROM events_with_experiment_column | |
) | |
SELECT variation_id, | |
COUNT(DISTINCT visitor_id) AS "unique_conversions", | |
COUNT(1) AS "total_conversion", | |
-- The currency sign ¤ is a character used to denote an unspecified currency. | |
'¤' || regexp_replace(replace(cast(SUM(revenue) / 100.0 as VARCHAR), '.', ','), '(\d)(?=(\d{3})+,)', '$1.') AS total_revenue | |
FROM events_with_all_columns | |
GROUP BY variation_id; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment