Friday, July 16, 2010

Finding top N rows

oracle supports specifying order by clause in select statement.
Suppose we what get top n rows by a specific value.

table Run(startTime, ID, priority). To get top N priority items

SELECT p,
startTime, ID
FROM (
SELECT row_number() OVER (ORDER BY priority DESC) p,
startTime, ID
FROM Run
WHERE r > N;


No comments:

Post a Comment