Skip to content

Instantly share code, notes, and snippets.

@johnhonan
Created December 7, 2017 19:49
Show Gist options
  • Save johnhonan/69d56b3c9c1f7243beea67b0fc29014e to your computer and use it in GitHub Desktop.
Save johnhonan/69d56b3c9c1f7243beea67b0fc29014e to your computer and use it in GitHub Desktop.
CASE statement and sub-query aggregate
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