|
Re: nth record from a sorted output of a table [message #18473 is a reply to message #18468] |
Fri, 01 February 2002 00:38  |
Mike
Messages: 417 Registered: September 1998
|
Senior Member |
|
|
From Oracle 8.1.6 or 8.1.7 on you got a new function which is very performant to do such things.
SELECT sal
FROM
( SELECT sal,
ROW_NUMBER() OVER (ORDER BY sal) s_rank
FROM emp
)
WHERE s_rank=4
Depending how you define the ranking you can also use RANK() or DENSE_RANK() instead of ROW_NUMBER() . The difference between RANK and DENSE_RANK is that DENSE_RANK leaves no gaps in ranking sequence when there are ties. That is, if you were ranking a competition using DENSE_RANK and had three people tie for second place, you would say that all three were in second place and that the next person came in third. The RANK function would also give three people in second place, but the next person would be in fifth place.
HTH
Mike
|
|
|