-
nth Salary Flow
Hi Guys, Can anybody let me understand how this query is working.
I am confused in flow of query.. Plz tell me how the flow is going on... Thanks in advance
select distinct(a.salary)
from employees a
where 2=(select count(distinct(b.salary))
from employees b
where a.salary<=b.salary);
-
What does the table look like? I'm guessing that the second column in the table is the number of people who make a certain salary.
-
Nth Salry
No its not like that.. ialso used explain plan but could not understand the flow
-
Originally Posted by umeshgupta1987
No its not like that.. ialso used explain plan but could not understand the flow
Do you grasp the "inline view" concept?
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
-
Nth salary Continuee...
I do understand the inline view concept.. But its a correlated sub query.. i m confused for only fetching the nth highest.. how we r getting that nth highest salary by providing 2 or 3 or something else.....
-
distinct() is defining salary levels.
inline view is counting how many lower salary levels are for each salary level.
main query is using counting as reference number a.k.a. Nth
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|