-
-
Save kiyoto/521160673fb876471232da986372e471 to your computer and use it in GitHub Desktop.
Percentile Usage User Segmentation
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 login_frequency AS ( | |
SELECT user_id, | |
COUNT(login) AS num_logins | |
FROM logins | |
GROUP BY user_id) | |
SELECT user_id, | |
CASE NTILE(4) OVER (ORDER BY num_logins) | |
WHEN 1 THEN ‘bottom_25’ | |
WHEN 4 THEN ‘top_25’ | |
ELSE ‘middle_50’ | |
END AS usage_segment | |
FROM login_frequency |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment