You are given employee and department data from an internal people analytics system. Write a PostgreSQL query to return the top three departments with the highest average employee salary, excluding departments that have fewer than five employees. The result should include the department name, employee count, and average salary, sorted by average salary from highest to lowest.
Output details
- Return columns named
department_name, employee_count, and avg_salary, in that order.
- Exclude employees whose
salary is NULL before calculating counts and averages.
- Round
avg_salary to exactly two decimal places.
- Break equal average-salary ties by
department_name in ascending alphabetical order.