1048ms clean solution


  • 0
    K
    SELECT
        d.`Name` AS `Department`, e.`Name` AS `Employee`, e.`Salary` AS `Salary`
      FROM `Employee` e
      LEFT JOIN `Department` d ON(d.`Id` = e.`DepartmentId`)
      INNER JOIN (
        SELECT `DepartmentId`, MAX(`Salary`) AS `Salary`
          FROM `Employee`
            GROUP BY `DepartmentId`
      ) AS e2 USING(`DepartmentId`, `Salary`)
        WHERE d.`Id`;

  • 0
    S

    Why need a inner join?
    I am new to SQL.


  • 1

    An Easy but Slow Solution :

    Select B.Name,A.Name,A.Salary from Employee A
    Inner Join Department B on A.DepartmentId=B.id
    where A.Salary = ( Select MAX(C.Salary) from Employee C Where A.DepartmentId =C.DepartmentId );
    

    It took me around 1366 ms to get Accepted .
    Hope it helps.


Log in to reply
 

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