RANK orders the members of a dimension based on the values of an expression. The function returns the sequence numbers of the dimension members.
RANK assigns the same rank to identical values, so there may be fewer ranks than there are dimension members. For example, RANK may return 1, 2, 3, 3, 4 for a series of five dimension members.
NUMBER
RANK (ntile_expression) OVER HIERARCHY
( dimension | hierarchy
ORDER BY expression [ASC | DESC] [NULLS {FIRST | LAST}]...
WITHIN {PARENT | LEVEL | ANCESTOR AT LEVEL level}
)
ntile_expression is not implemented in this function.
dimension is the dimension whose members are being ranked.
hierarchy is a hierarchy of dimension. Otherwise, the default hierarchy is used.
ORDER BY provides the basis for the ranking. You can provide additional ORDER BY clauses to break any ties in the order.
expression provides the values to use as the basis for the rankings.
ASC creates the ranking from smallest to largest data values.
DESC
CUSTOMER |
LEVEL_NAME |
UNITS |
RANK |
|---|---|---|---|
| Asia Pacific | REGION | 138782 |
-- |
| Computer Services Tokyo | SHIP_TO | 63812 |
8 |
| Computer Warehouse Singapore | SHIP_TO | 51454 |
7 |
| KOSH Entrpr Tokyo | SHIP_TO | 14336 |
6 |
| KOSH Entrpr Brisbane | SHIP_TO | 3069 |
5 |
| KOSH Entrpr Wanchai | SHIP_TO | 2970 |
4 |
| KOSH Entrpr Bristol | SHIP_TO | 2446 |
3 |
| Ministry of Intl. Trad Nagoya | SHIP_TO | 357 |
2 |
| Ministry of Intl. Trad Nagano | SHIP_TO | 338 |
1 |
| Japan | WAREHOUSE | 78843 |
4 |
| Singapore | WAREHOUSE | 51454 |
3 |
| Australia | WAREHOUSE | 5515 |
2 |
| Hong Kong | WAREHOUSE | 2970 |
1 |
creates the ranking from largest to smallest data values.
NULLS FIRST lists the members with null values first.
NULLS LAST lists the members with null values last.
WITHIN selects a set of related dimension members to be ranked.
PARENT ranks members at the same level with the same parent.
LEVEL ranks all members at the same level.
ANCESTOR AT LEVEL level ranks all members at the same level and with the same parent at a specified level.
The following example ranks customers by level within each region based on the values of the UNITS measure.
RANK () OVER HIERARCHY (GLOBAL.CUSTOMER.SHIPMENTS_ROLLUP ORDER BY GLOBAL.UNITS_CUBE.UNITS NULLS LAST WITHIN ANCESTOR AT LEVEL GLOBAL.CUSTOMER.REGION)
CUSTOMER |
LEVEL_NAME |
UNITS |
RANK |
|---|---|---|---|
| Asia Pacific | REGION | 138782 |
-- |
| Computer Services Tokyo | SHIP_TO | 63812 |
8 |
| Computer Warehouse Singapore | SHIP_TO | 51454 |
7 |
| KOSH Entrpr Tokyo | SHIP_TO | 14336 |
6 |
| KOSH Entrpr Brisbane | SHIP_TO | 3069 |
5 |
| KOSH Entrpr Wanchai | SHIP_TO | 2970 |
4 |
| KOSH Entrpr Bristol | SHIP_TO | 2446 |
3 |
| Ministry of Intl. Trad Nagoya | SHIP_TO | 357 |
2 |
| Ministry of Intl. Trad Nagano | SHIP_TO | 338 |
1 |
| Japan | WAREHOUSE | 78843 |
4 |
| Singapore | WAREHOUSE | 51454 |
3 |
| Australia | WAREHOUSE | 5515 |
2 |
| Hong Kong | WAREHOUSE | 2970 |
1 |
AVERAGE_RANK, DENSE_RANK, ROW_NUMBER
Copyright © 2003, 2007, Oracle. All rights reserved.