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
How to test for null values?
How does sql developer connect to oracle database?
What is varchar example?
Is sql sequential or random?
Are views faster than queries?
what is a composite key ? : Sql dba
how to write date and time literals? : Sql dba
How to return multiple rows from the stored procedure?
How do you write a complex sql query?
Can we create view in stored procedure?
When are we going to use truncate and delete?
What is %s in sql?
How does postgresql compare to mysql?
what is normalization? : Sql dba
what are the drivers in mysql? : Sql dba