Second Highest Salary

后端 未结 10 1571
无人共我
无人共我 2020-12-20 06:14

Write a SQL query to get the second highest salary from the Employee table.

    | Id | Salary |
    | 1  | 100    |
    | 2  | 200    |
    | 3  | 300    |
<         


        
10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-20 06:49

    You can use RANK() function to rank the values for Salary column.

    SELECT *
    FROM
    (
     SELECT *, RANK()OVER(ORDER BY Salary DESC) As SalaryRank
     FROM Employee 
    ) AS Tab
    WHERE SalaryRank = 2
    

提交回复
热议问题