Results 1 to 2 of 2

Thread: qry

  1. #1
    Join Date
    Sep 2002
    Posts
    17

    Unanswered: qry

    how to get the Nth max sal

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: qry

    Originally posted by karraaruna
    how to get the Nth max sal
    Is this homework? I shouldn't really be helping!

    One way:
    SELECT sal FROM
    ( SELECT DISTINCT sal, ROWNUM rn
    FROM emp
    ORDER BY sal DESC
    )
    WHERE rn = :n;

    Another way (if I have got this right):

    SELECT sal FROM
    ( SELECT DISTINCT sal, DENSE_RANK() OVER (ORDER BY sal DESC) dr
    FROM emp
    )
    WHERE dr = :n;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •