DBAsupport.com Forums - Powered by vBulletin
Results 1 to 6 of 6

Thread: nth Salary Flow

  1. #1
    Join Date
    Apr 2010
    Posts
    3

    Unhappy 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);

  2. #2
    Join Date
    Nov 2000
    Location
    Pittsburgh, PA
    Posts
    4,166
    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.

  3. #3
    Join Date
    Apr 2010
    Posts
    3

    Unhappy Nth Salry

    No its not like that.. ialso used explain plan but could not understand the flow

  4. #4
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,555
    Quote Originally Posted by umeshgupta1987 View Post
    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.

  5. #5
    Join Date
    Apr 2010
    Posts
    3

    Unhappy 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.....

  6. #6
    Join Date
    Mar 2007
    Location
    Ft. Lauderdale, FL
    Posts
    3,555
    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
  •  


Click Here to Expand Forum to Full Width