You can also create a general solution for this top X problem

  • 0

    SELECT D.Name Department, E.Name Employee, E.Salary Salary
    Employee E,
    Department D
    WHERE E.DepartmentId = D.Id
    (SELECT COUNT(DISTINCT Salary) FROM Employee WHERE E.Salary < Salary AND E.DepartmentId = DepartmentId) < 1

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.