Hi,
Can anybody please explain me the flow of the below query.
I am not able to understand how this query works.
This query is for finding the Nth highest salary..
SELECT DISTINCT (a.sal)
FROM EMP A
WHERE &N = (SELECT COUNT (DISTINCT (b.sal)) FROM EMP B
WHERE a.sal<=b.sal);
If N = 2 then second highest salary will be the o/p.
If N = 3 then third highest salary will be the o/p.
and so on..
Thanks,
Nitin
Answer Posted / ms75
Detailed answer available on following weblinks
-----------------------------------------------
1) How does this query work?
<http://www.sqlteam.com/article/find-nth-maximum-value-in-
sql-server>
2) How this query works?
<http://www.dbapool.com/forumthread/topic_4361.html>
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
What are different types of queries in sql?
explain access control lists. : Sql dba
Why do we use partitions in sql?
What is a record in a database?
what are the type of locks ? : Sql dba
What is a sql select statement?
Is sql pronounced sequel or sql?
What is a stored procedure in sql with example?
what are the other commands to know the structure of table using mysql commands except explain command? : Sql dba
Can %notfound return null after a fetch?
List the ways to get the count of records in a table?
what is a cursor? : Sql dba
What is data profiling in sql?
What is t sql used for?
what is the difference between char_length and length? : Sql dba