Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Departments by Average Salary

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Top Departments by Average Salary. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

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.

Schema

departments
ColumnTypeDescription
department_idPKINTUnique identifier for a department
department_nameVARCHAR(100)Department name
employees
ColumnTypeDescription
employee_idPKINTUnique identifier for an employee
employee_nameVARCHAR(100)Employee full name
department_idINTDepartment assigned to the employee
salaryDECIMAL(10,2)Employee salary
Tablesdepartmentsemployees
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results