Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Departments by Average Salary

MediumSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: Top Departments by Average Salary. Read through the requirements and the two tables first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

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