Write a query to find second highest salary of an employee.

Answer Posted / biswojit kar

Getting nth max sal of an Employee.

select sal from (select ename,sal, dense_rank() over(order
by sal desc nulls last) as rank from emp) where rank=n;

Here n = 2 for 2nd highest sal, 3 for 3rd highest sal, 4
for 4th highest sal and so on.One can use rank() in place
of dense_rank(), but the demerit of rank() is as follows:
Let you want to see 3rd highest sal.
Suppose 2 employees have 2nd highest sal, then rank()
assigns both of them rank 2, then it leaves a gap and
assigns the emp with 3rd highest sal to rank 4.
So, when you use the above query with rank(), the you donot
get the 3rd highest sal. Try retrieving 3rd highest sal in
emp table in scott user, using both rank() and dense_rank
(), and mark the diff. Thanks!

Is This Answer Correct ?    2 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Name some of the commonly used automation testing tools that are used for functional automation.

525


Please explain what is the hybrid framework?

592


is anybody suggest me which one is the best testing institute in ameerpet hydrabad

1736


Tell us what is the difference between getwindowhandles() and getwindowhandle()?

510


Kindly let me know how to setup JMeter for functionality testing of a Web application.. The apache help doc is good but i m little confused with it... :(

1753






What are the main differences between Loadrunner and QTP tools? Describe briefly a "real world" scenario that would make you use the first one versus the other? Thank you for your answers....

2322


VSTET (Visual Studio Team Edition for Testers) which is in TFS (Team Foundation Server) - In what way is VSTET better than QTP?

3210


Tell us what is the difference between @factory and @dataprovider annotation?

526


What is functional and regression testing?

627


Explain what is the hybrid framework?

578


what are the steps followed in unit testing, system testing, integration testing

1553


Explain what sikuli is?

610


How can the user get a text of a web element?

532


HOW DO YOU PERFORM SECURITY TESTING TO VERIFY FIREWALLS,PASWORD ENCRYPTOPNS ETC?

1832


Could any one share scripts... where we can Parameterize radio buttons and Check boxes in Rational Robot.

1622