Skip to content

Instantly share code, notes, and snippets.

@czeildi
Created February 13, 2018 13:05
Show Gist options
  • Save czeildi/5757b42b7a87e849f4c2d2dbac05d968 to your computer and use it in GitHub Desktop.
Save czeildi/5757b42b7a87e849f4c2d2dbac05d968 to your computer and use it in GitHub Desktop.
cumulative unique n in bigquery sql
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