Second Highest Salary

后端 未结 10 1528
无人共我
无人共我 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 07:04

    SELECT id, MAX(salary) AS salary 
    FROM employee 
    WHERE salary IN
    (SELECT salary FROM employee MINUS SELECT MAX(salary) 
    FROM employee); 
    

    You can try above code to find 2nd maximum salary. The above code uses MINUS operator. For further reference use the below links https://www.techonthenet.com/sql/minus.php https://www.geeksforgeeks.org/sql-query-to-find-second-largest-salary/

提交回复
热议问题