RANK(position, set [ ,DESCEND ])
position | An integer indicating the element in the sorted set to return. |
set | The set of values. |
DESCEND | Optional. Indicates descending order sort. |
Return: | RANK returns a single value. |
The RANK function sorts the set in ascending (or descending, if DESCEND is present) order, then returns the ordinal position (its index value) of the unsorted set's position element after the set has been sorted. This is the opposite of RANKED.
Example:
Ranking1 := RANK(1,[20,30,10,40]);
// returns 2 - 1st element (20) in unsorted set is
// 2nd element after sorting to [10,20,30,40]
Ranking2 := RANK(1,[20,30,10,40],DESCEND);
// returns 3 - 1st element (20) in unsorted set is
// 3rd element after sorting to [40,30,20,10]
OUTPUT(Ranking1);
OUTPUT(Ranking2);
See Also: RANKED, SORT, SORTED, Sets and Filters