My solution using inner join


  • 0
    H
    SELECT dep.Name AS Department, emp.Name AS Employee, emp.Salary FROM Employee emp
    INNER JOIN (
        SELECT DepartmentId AS did, MAX(Salary) AS Salary FROM Employee GROUP BY DepartmentId
    ) AS mse ON emp.DepartmentId = mse.did AND emp.Salary = mse.Salary
    INNER JOIN Department AS dep
    ON emp.DepartmentId = dep.id

  • 0
    E

    select tb2.Name as Department,tb1.Name as Employee,tb1.Salary as Salary
    from Employee tb1,Department tb2
    where(tb1.DepartmentId,tb1.Salary ) IN (select DepartmentId,max(Salary) as maxSalary from Employee
    group by DepartmentID) and tb1.DepartmentId=tb2.Id;


Log in to reply
 

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