calculate 2nd highest salary sql code example
Example 1: second max salary in sql
SELECT MAX(SALARY) 'SECOND_MAX' FROM EMPLOYEES
WHERE SALARY <> (SELECT MAX(SALARY) FROM EMPLOYEES);
Example 2: third highest salary in sql
SELECT * FROM Employee WHERE sal =
(
SELECT MIN(sal) FROM Employee
WHERE sal IN (
SELECT DISTINCT TOP N
sal FROM Employee
ORDER BY sal DESC
)
)