1) options 1 (without using LIMIT function )
Answer :
SELECT MAX(Salary) From Employee WHERE Salary < ( SELECT Max(Salary) FROM Employee);
2) options 2 (without using LIMIT function )
Answer :
SELECT TOP 1 Salary FROM ( SELECT TOP 2 Salary FROM Employee ORDER BY Salary DESC) AS MyTable ORDER BY Salary ASC;
3) options 3 (using LIMIT function )
Answer :
GENERIC SOLUTION USING DENSE_RANK
select * from(select ename, salary, dense_rank() over(order by salary desc)r from Emp) where r=2
change the r=3 for 3RD Highest salary
change the r=3 for 3RD Highest salary
r=4 for 4 th Highest salary ,,, and so on
No comments:
Post a Comment