Created
September 20, 2018 15:47
-
-
Save mhkeller/2bcd8f476b80f8bc7430e55b12a59322 to your computer and use it in GitHub Desktop.
Calculat quantile amounts based on aggregate counts. Adapted from https://gist.github.com/hrwgc/5171860
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 | |
ntile, | |
avg(ct) AS avgAmount, | |
max(ct) AS maxAmount, | |
min(ct) AS minAmount, | |
median(ct) as median | |
FROM (SELECT ct, ntile(5) OVER (ORDER BY ct) AS ntile FROM (select count(col_name) as ct from table GROUP BY col_Name) t) x | |
GROUP BY ntile | |
ORDER BY ntile; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment