Skip to content

Instantly share code, notes, and snippets.

@ks--ks
Last active May 6, 2023 18:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ks--ks/7edf477ad699996a6d9433902dcb54ba to your computer and use it in GitHub Desktop.
Save ks--ks/7edf477ad699996a6d9433902dcb54ba to your computer and use it in GitHub Desktop.
User Engagement Histogram
SELECT active.num_days_active
, COUNT(DISTINCT active.user_id) AS num_users -- get how many users have a number of active days
FROM (
SELECT a.user_id, COUNT(DISTINCT a.created_at) AS num_days_active
FROM activity a
GROUP BY a.user_id) AS active
LEFT JOIN activity a2 ON a2.user_id = active.user_id
WHERE a2.created_at >= CURRENT_DATE - 28
GROUP BY active.num_days_active
ORDER BY active.num_days_active ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment