PLEASE ..VERY URGENT..HOW TO FIND THE NTH SALARY FROM A TABLE

  • PLEASE ..VERY URGENT..HOW TO FIND THE NTH SALARY FROM A TABLE

  • Hope this helps..

    Select * From Employee E1 Where

    (N-1) = (Select Count(Distinct(E2.Salary)) From Employee E2 Where

    E2.Salary > E1.Salary)

    Brij

  • I imagine that the original poster want the Nth salary, ie the one with N - 1 salaries higher than it, whether they be distinct or not.

    This one is a little more compact, and I think it may perform better if your table is large.  I have used the roysched table from the pubs database as an example; please adapt to suit your needs.

    SELECT TOP 1 royalty

    FROM (SELECT TOP 5 royalty FROM roysched ORDER BY royalty) x

    ORDER BY royalty DESC

    John

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply