How to get second-highest salary employees in a table

后端 未结 30 993
离开以前
离开以前 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:04

    I want to post here possibly easiest solution. It worked in mysql.

    Please check at your end too:

    SELECT name
    FROM `emp`
    WHERE salary = (
    SELECT salary
    FROM emp e
    ORDER BY salary DESC
    LIMIT 1
    OFFSET 1 
    

提交回复
热议问题