Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Top Departments by Average Salary
00:00
5 left

Top Departments by Average Salary

MediumSQL · PostgreSQL

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
Interviewer

Your question is Top Departments by Average Salary. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.