Created
December 7, 2017 19:49
-
-
Save johnhonan/69d56b3c9c1f7243beea67b0fc29014e to your computer and use it in GitHub Desktop.
CASE statement and sub-query aggregate
This file contains hidden or 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 salary_group, count(*) FROM | |
(SELECT | |
employee_id, | |
last_name, | |
CASE | |
WHEN salary <= 3000 THEN 'poor' | |
WHEN salary >3000 AND salary <= 11000 THEN 'okay' | |
WHEN salary > 11000 THEN 'rich' | |
ELSE 'Theres a problem' | |
END AS salary_group | |
FROM hr.employees) x | |
GROUP BY salary_group; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment