FastPrepTop Salaries By Department
Problem · Database

Top Salaries By Department

EasyZS logoZSNEW GRADONSITE INTERVIEW

Problem statement

The table employees stores one row per employee, including that employee's department and salary.

For each department, find the highest salary. Return every employee who earns that department-highest salary, including all employees tied at the top.

Return department_id, employee_id, employee_name, and salary. Order rows by department_id ascending, then employee_id ascending.

What the interview report shared

The interviewer asked SQL to find the top salaries by department.

employees
ColumnMeaning
employee_idUnique employee identifier
employee_nameEmployee display name
department_idDepartment identifier
salaryEmployee salary

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.

employees

One row per employee.

ColumnTypeNullableDescription
employee_idPKIntegerNo
employee_nameTextNo
department_idIntegerNo
salaryIntegerNo

Expected result

Your query or function must return these columns.

ColumnTypeNullableDescription
department_idIntegerNo
employee_idIntegerNo
employee_nameTextNo
salaryIntegerNo

Row order: must match exactly. Numeric tolerance: 0.

Constraints

  • The employees table has between 1 and 10^5 rows.
  • employee_id is unique and non-null.
  • employee_name, department_id, and salary are non-null.
  • 0 <= salary <= 10^9.

More ZS problems