Filter Departments By Average Salary Comparison

Find departments whose average salary is greater than the company-wide average salary.

sql

SELECT department_name, AVG(salary) AS avg_dept_salary FROM employees GROUP BY department_name HAVING AVG(salary) > (SELECT AVG(salary) FROM employees);

This query groups the "employees" table by "department_name" to calculate the average salary per department and uses a subquery in the HAVING clause to filter for those departments where the average salary exceeds the global average salary of all employees.

PromptDB can make mistakes. Please double-check responses.