SOLUTION1
select * from ( select ename,sal,dense_rank() over (order by sal desc) rank from emp) where rank=2
SOLUTION2
select * from ( select ename,sal,deptno,dense_rank() over (partition by deptno order by sal desc) rank from emp) where rank=2
SOLUTION3
SELECT * FROM emp a WHERE (&n-1)=(SELECT count(DISTINCT b.sal) FROM emp bWHERE a.sal<b.sal);
SOLUTION4
To find the nth highest salary and find the second largest value in a given column as you asked both are same. So, both of the above scenarios the below is the query:
SELECT * FROM table_name a WHERE &n=(SELECT count(DISTINCT(sal)) FROMTable_name b WHERE a.sal<b.sal);
|