Last active
December 6, 2022 16:14
-
-
Save ryandhubbard/566d64ba07ea1b62dc6c3bcb1825607c to your computer and use it in GitHub Desktop.
Bucket Value
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 COUNT(1) AS total | |
, CASE | |
WHEN measure <= 0 THEN '0-10' | |
WHEN measure <= 100 THEN CONCAT(CEIL(measure/10)*10-10,'-',CEIL(measure/10)*10) | |
WHEN measure <= 30000 THEN CONCAT(CEIL(measure/50)*50-50,'-',CEIL(measure/50)*50) | |
WHEN measure > 30000 THEN 'over 30000' | |
ELSE NULL | |
END AS bucket | |
, CASE | |
WHEN measure <= 100 THEN CEIL(measure/10)*10 | |
WHEN measure <= 30000 THEN CEIL(measure/50)*50 | |
WHEN measure > 30000 THEN 30001 | |
ELSE 0 | |
END AS sort_no_use | |
FROM TABLE | |
WHERE 1 | |
GROUP BY bucket | |
ORDER BY sort_no_use |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment