My solution


  • 0
    W

    '''
    select D.Name as 'Department', S.Name as 'Employee', S.Salary
    from (SELECT
    Name,
    @rankId := IF( @departmentId=DepartmentId , IF (@salary > Salary, @rankId +1, @rankId ) , 1) as 'rankId',
    @departmentId := DepartmentId as 'DepartmentId' ,
    @salary := Salary as 'Salary'
    FROM Employee , (SELECT @rankId := 1, @departmentId := 0, @salary := 0) as t
    order by DepartmentId, Salary desc ) as S
    JOIN Department D on D.Id = S.DepartmentId

    WHERE rankId <4
    order by S.DepartmentId, S.rankId
    '''


Log in to reply
 

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