Skip to content

Instantly share code, notes, and snippets.

@ivanpk
Last active February 5, 2020 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivanpk/fb84a2c4a8550bd2cf49361d3b559ce1 to your computer and use it in GitHub Desktop.
Save ivanpk/fb84a2c4a8550bd2cf49361d3b559ce1 to your computer and use it in GitHub Desktop.
WITH daily AS (
SELECT
DATE(created_at) day,
user_id
FROM
`example-project.ivan.article_example_dataset`
)
SELECT
day,
SUM(APPROX_COUNT_DISTINCT(user_id)) OVER (ORDER BY day ROWS BETWEEN 89 PRECEDING AND CURRENT ROW) ninty_day_window_approx
FROM
daily
GROUP BY
1
ORDER BY
1 DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment