Last active
July 31, 2019 10:04
-
-
Save CremboC/f6434187bd2e5b9817ac3efb3073d76f 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 base_users AS ( ... ), | |
country_users AS ( ... ), | |
todays_users AS ( | |
SELECT | |
HLL_COUNT.INIT(user_id, 19) as sketch | |
FROM pageview_events | |
WHERE | |
_PARTITIONTIME = TIMESTAMP_TRUNC(CURRENT_TIMESTAMP(), DAY) | |
country = ... | |
) | |
SELECT | |
HLL_COUNT.MERGE(a) + HLL_COUNT.MERGE(b) - HLL_COUNT.MERGE(ab) AS users_size | |
FROM ( | |
( | |
SELECT | |
sketch AS a, | |
NULL AS b, | |
sketch AS ab | |
FROM base_users | |
) UNION ALL ( | |
SELECT | |
NULL AS a, | |
sketch AS b, | |
sketch AS ab | |
FROM country_users | |
) UNION ALL ( | |
SELECT | |
sketch AS a, | |
sketch AS b, | |
sketch AS ab | |
FROM todays_users | |
WHERE "[Include_Todays_Data|1]"="1" | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment