β¨ Programming
Medium
SQL Aggregates
Departments With Average Salary Above 80,000
Question
Find all departments where the average employee salary exceeds 80,000. Return department name and average salary rounded to 2 decimal places.
Use the employees table.
Solution
SELECT
department,
ROUND(AVG(salary), 2) AS avg_salary
FROM employees
GROUP BY department
HAVING AVG(salary) > 80000
ORDER BY avg_salary DESC;
Explanation: GROUP BY department, compute AVG(salary), then filter groups with HAVING AVG(salary) > 80000.