Departments With the Highest Average Salary
Updated
Problem statement
A company stores its staff in two tables, Employee and Departments. Find the department, or departments, whose employees have the highest average salary.
Example: Engineering pays 90 and 300, so its average is 195. Sales pays 200, 200 and 200, so its average is 200. Sales wins, even though Engineering has the single highest salary.
Return one row for each winning department, with its id and name.
- A department's average is the total salary of its employees divided by the number of its employees.
- If several departments share the highest average, return all of them.
- A department with no employees has no average. Never return it.
- If there are no employees at all, return no rows.
- The rows can be in any order.
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
Departments
| Column | Type | Nullable | Description |
|---|---|---|---|
| idPK | Integer | No | — |
| name | Text | No | — |
Employee
| Column | Type | Nullable | Description |
|---|---|---|---|
| idPK | Integer | No | — |
| department_id | Integer | No | — |
| salary | Integer | No | — |
Foreign key: department_id → Departments(id)
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| id | Integer | No | — |
| name | Text | No | — |
Row order: any order is accepted. Numeric tolerance: 0.
Constraints
- The tables are
Employee(id, department_id, salary)andDepartments(id, name). idis a unique positive integer in each table.Employee.department_idis theidof a row inDepartments.salaryis an integer from0to1000000.nameis text of 1 to 50 characters. Names can repeat, so a department is identified by itsid.Employeehas at most2000rows andDepartmentshas at most200rows. Either table can be empty.- Each department has at most
99employees.
More Bloomberg LP Phone Screen questions
- N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fewest Coins CombinationPHONE SCREEN · Seen Nov 2026
- Recommend Films from Viewers Who Watched Everything You DidPHONE SCREEN · Seen Nov 2026
- Track New Values in Sorted OrderPHONE SCREEN · Seen Nov 2026
- Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Sparse Vector and Matrix OperationsPHONE SCREEN · Seen Oct 2026
- Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Second Highest SalaryPaytm · PHONE SCREENPaytm interview questions
- Employees Who Earn More Than Their ManagersNykaa · PHONE SCREENNykaa interview questions
- Employees Who Joined More Than a Week AgoNewgen Software · PHONE SCREEN
- Departments Without EmployeesDell Technologies · PHONE SCREENDell Technologies interview questions
- Second-Highest Distinct SalaryChubb · PHONE SCREENChubb interview questions
- Swap Two Gender ValuesInfosys · PHONE SCREENInfosys interview questions
- Find Rows Common to Two TablesSalesforce · PHONE SCREENSalesforce interview questions
- Count Records Present in A but Not BCapital One · PHONE SCREENCapital One interview questions
- Customer Order Count Distribution by CountryApple · PHONE SCREENApple interview questions
- Employees Earning More Than Their ManagerMygate · PHONE SCREENMygate interview questions
Interview reports that mention this question
Bloomberg LP interview experiences
- Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Interview Questions, Level Not Reported: 65 Questions
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)