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
What are Keyword and Data driven frameworks in Selenium RC
What are the disadvantages of Hybrid framework
Tell me which web driver implementation is the fastest?
Types of F/w in Automation
Elaborate the scripting standard while executing testing
What is functional and regression testing?
List down the primary features of a good automation tool?
Please explain what is a relative xpath?
Do you know how to check if a button is enabled on the page?
What all things can you automate?
What is the difference between close and quit command?
What are the important operations in database testing?
What is junit? And what is junit annotation?
What is modular automation?
what is GDC