how to find nth highest salary
Answer Posted / saravanan
The below 2 queries will work
n - The nth highest salary
First query
------------------------
SELECT MAX(salary)
FROM
(SELECT salary
FROM emp
WHERE salary IS NOT NULL
ORDER BY salary DESC)
WHERE rownum < &n;
Second query
------------------------
SELECT DISTINCT(a.salary)
FROM emp a
WHERE &n =
(SELECT COUNT(DISTINCT(b.salary))
FROM emp b
WHERE a.salary <= b.salary)
;
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What are types of subqueries?
How to skip remaining statements in a loop block using continue statements?
Do you know hot add cpu in sql server 2008?
What is a View ? Can we insert, Update and delete a view?
Do you know what are pages and extents? : SQL Server Architecture
What is the difference between value type and reference type?
What is dbcc command in sql server?
Tell me the use of keyword with encryption. Create a store procedure with encryption?
If no size is defined while creating the database, what size will the database have?
How many null values we can have in a unique key field in sql server?
What do you mean by collation recursive stored procedure?
Explain the various types of concurrency problem. I.e. Lost or buried updates, uncommitted dependency, inconsistent analysis, phantom read?
What are functions in the sql server?
Explain what are the database objects? : SQL Server Architecture
What is the importance of concurrency control?