Write a SQL block that will categorize Employee Salaries. If the Salary is higher than average, it will show ‘Above Average’ to the output. If the Salary is lower than the average it will show ‘Below average’ to the output. Use HR.Employees Table. Also, utilize CASE statement.
SELECT employee_id,
CASE
WHEN salary > (SELECT AVG(salary) FROM hr.employees)
THEN 'Above Average'
WHEN salary < (SELECT AVG(salary) FROM hr.employees)
THEN 'Below Average'
ELSE 'Average'
END AS salary_comparison
FROM hr.employees
order by salary_comparison;
-- Ref: with a bit of information from the Internet