Second Highest Salary

后端 未结 10 1569
无人共我
无人共我 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:59

    In case of ties you want the second highest distinct value. E.g. for values 100, 200, 300, 300, you want 200.

    So get the highest value (MAX(salary) => 300) and then get the highest value less than that:

    select max(salary) from mytable where salary < (select max(salary) from mytable);
    

提交回复
热议问题