How to get second-highest salary employees in a table

后端 未结 30 968
离开以前
离开以前 2020-12-23 20:15

It\'s a question I got this afternoon:

There a table contains ID, Name, and Salary of Employees, get names of the second-highest salary employees, in SQL Server

30条回答
  •  一生所求
    2020-12-23 21:12

    If you want to display the name of the employee who is getting the second highest salary then use this:

    SELECT employee_name 
    FROM employee
    WHERE salary = (SELECT max(salary) 
                    FROM employee
                    WHERE salary < (SELECT max(salary) 
                                    FROM employee);
    

提交回复
热议问题