自己的答案:
SELECT MAX(TMP.SALARY) AS SecondHighestSalary
FROM (
SELECT SALARY AS SALARY
FROM EMPLOYEE
WHERE SALARY != (
SELECT MAX(SALARY)
FROM EMPLOYEE
)
) TMP;
网上答案,使用偏移实现。
select (
select distinct Salary
from Employee
order by Salary desc
limit 1 offset 1
) as SecondHighestSalary;
网上答案是使用limit实现,limit 通常我们使用时候只给一个参数,该参数则表示返回的记录数;但是limit支持两个参数,例如:limit 1,2 含义是从记录index=1的位置开始返回两个技术。(index默认值为0)