Created
February 13, 2018 13:05
-
-
Save czeildi/5757b42b7a87e849f4c2d2dbac05d968 to your computer and use it in GitHub Desktop.
cumulative unique n in bigquery sql
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 | |
customer_id | |
, launch_at | |
, count(is_first_occurence) over (ORDER BY launch_at) preceeding_customer_count | |
FROM | |
( | |
SELECT | |
customer_id | |
, launch_at | |
, (CASE WHEN row_number() over ( PARTITION BY customer_id ORDER BY launch_at) = 1 THEN 1 ELSE NULL END) AS is_first_occurence | |
FROM | |
[table_with_launches] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment