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
Explain about merge replications?
Explain indexes disadvantages?
How to connect ms access to sql servers through odbc?
How do we upgrade from SQL Server 6.5 to 7.0 and 7.0 to 2000?
What extended events?
What are the disadvantages of using querystrings to send data from one page to another?
How to insert multiple rows with one insert statement in ms sql server?
What is dirty page?
Explain Capacity planning to create a database? and how to monitor it?
What is read committed?
how can u get last observation in an unknown dataset ?
What is the difference between primary key and unique constraints?
What are the components of dbms?
how to take backup bcp out for a column in table in sql server?
Can you please explain the difference between function and stored procedure?