Solution without in-built function


  • 0
    E
    SET @A = 0;
    SET @B = 0;
    SELECT MIN(T1.ID) AS ID, T1.COMPANY AS COMPANY, T1.SALARY
    FROM (SELECT ID, COMPANY, SALARY, @A := @A + 1 AS VID FROM EMPLOYEE ORDER BY COMPANY ASC, SALARY ASC) T1,
         (SELECT ID, COMPANY, SALARY, @B := @B + 1 AS VID FROM EMPLOYEE ORDER BY COMPANY ASC, SALARY DESC) T2
    WHERE (T1.VID = T2.VID OR T1.VID = T2.VID -1 OR T1.VID = T2.VID + 1) AND T1.ID = T2.ID
    GROUP BY T1.COMPANY, T1.SALARY
    

Log in to reply
 

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