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 do you understand by check constraint in sql server?
How to create a local temporary stored procedure?
Can you force a query to use a specific index?
How to compose an inquiry to demonstrate the points of interest of an understudy from students table whose name begins with k?
how we use window authentication connection with sql server.?
What is the usage of sign function?
Explain system scalar functions?
what are the different stages of Report Processing?
What are indexes in sql?
What is an execution plan? When would you use it?
How do I manually uninstall an instance of sql server 2016?
How you can get a list of all the table constraints in a database? : Sql server administration
Explain differentiate between a having clause and a where clause?
What is a virtual table in sql?
State a few properties of relational databases?