Important
The SingleStore 9.1 release candidate (RC) is available now. It will be promoted to general availability (GA) soon and at that time it will be renamed to SingleStore 10.
In the interim, SingleStore 9.1 RC can be used to preview, evaluate, and provide feedback on the new and upcoming features in SingleStore 10, while SingleStore 9.0 is recommended for production workloads.
RANK
On this page
The RANK() function returns the rank of the current row within the partition as specified by the order by clause.
If two or more rows tie they have the same ranking.
Syntax
RANK () OVER (
[PARTITION BY (col | expr), ...]
[ORDER BY (col | expr), ...]
)Return Type
An integer
Example
The following example demonstrates how the partition clause groups results and then rank is applied to those groups.
CREATE TABLE rank_t (a int, b int);INSERT INTO rank_t VALUES(1,1), (1,2), (3,2), (3,3), (3,-4);
SELECT a,b, RANK() OVER (PARTITION BY a ORDER BY b) FROM rank_t;
+------+------+-----------------------------------------+
| a | b | RANK() OVER (PARTITION BY a ORDER BY b) |
+------+------+-----------------------------------------+
| 1 | 1 | 1 |
| 1 | 2 | 2 |
| 3 | -4 | 1 |
| 3 | 2 | 2 |
| 3 | 3 | 3 |
+------+------+-----------------------------------------+Last modified: