![]() |
|
|
Published: Wednesday, November 04, 1998 By Scott Mitchell
Introduction
Getting the Results of a Table with Rank Let's say that we have a table which is defined as follows:
Here is the script which will return all of the rows in ranked order:
SELECT rank, ItemNumberID, Cost
FROM (SELECT T1.ItemNumberID, T1.Cost,
(SELECT COUNT(DISTINCT T2.Cost) FROM ItemCost T2
WHERE T1.Cost <= T2.Cost) AS rank
FROM ItemCost T1) AS X
ORDER BY rank
To get the top N rows, all you would need to do is put:
right before your
The SQL query above is especially useful if you are interested in a particular subset of the ranked records. For example, you
can grab the second ranked item using Happy Programming!!
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||