Department Highest Salary

4pts
Google

Problem Statement

Google HR needs to identify the highest-paid individuals in every department for budget reviews. Note that multiple employees can share the highest salary in a department; in such cases, all of them should be reported.

Write an SQL query to find employees who have the highest salary in each of the departments.

Rules:

  • Return the result table with columns Department, Employee, and Salary.
  • If there is a tie for the highest salary in a department, include all employees with that salary.
  • Results must be sorted by Department name in ascending order.
Tests your understanding of
Basic SQL, Window Functions, Joins, RANK and Grouping

Input Tables

employee
id(INTEGER)name(VARCHAR)salary(INTEGER)department_id(INTEGER)
1Joe700001
2Jim900001
3Henry800002
4Sam600002
5Max900001
6Janet690001
department
id(INTEGER)name(VARCHAR)
1IT
2Sales

Expected Output

Department(VARCHAR)Employee(VARCHAR)Salary(INTEGER)
ITJim90000
ITMax90000
SalesHenry80000

Tags

MediumBasic SQLWindow FunctionsJoinsRANKGrouping
15-20 min
52%

Hints