Created
April 2, 2024 10:07
-
-
Save lfy79001/3a5b71fd4faf04496f733abfec4c02f3 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
WITH impression_stats AS ( | |
SELECT | |
event.country_domain_name AS country, | |
CONCAT(event.country_domain_name, '-', event.state) AS state, | |
COUNT(DISTINCT user_id) AS users, | |
COUNT(*) AS impressions | |
FROM adh.cm_dt_impressions | |
WHERE event.country_domain_name = 'US' | |
OR event.country_domain_name = 'CA' | |
GROUP BY 1, 2 | |
) | |
SELECT | |
country, | |
IFNULL(state_name, state) AS state_name, | |
users, | |
impressions, | |
FORMAT( | |
'%0.2f', | |
IF( | |
IFNULL(impressions, 0) = 0, | |
0, | |
impressions / users | |
) | |
) AS avg_imps_per_user | |
FROM impression_stats | |
LEFT JOIN adh.cm_dt_state USING (state) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment