By ranking the salary by groups


  • 0
    V

    '''
    select c.Id,c.Company, c.Salary from (
    select a.Id, a.Salary,b.number,b.Company
    , (CASE a.Company
    WHEN @curType THEN @curRow := @curRow + 1
    ELSE @curRow := 1 AND @curType := a.Company END
    ) + 1 AS rank

    from (select Id, Company, Salary from employee order by Company, Salary, Id) a
    inner join (SELECT @curRow := 0, @curType := '') r
    inner join
    (select Company, count(salary) as number from employee
    group by Company ) b
    on a.Company=b.Company
    ) c

    where case when c.number%2=0 then c.rank=c.number/2 or c.rank=c.number/2+1
    else c.rank=round(c.number/2)
    end
    '''


Log in to reply
 

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