Outdated Version
You are viewing an older version of this section. View current production version.
RANK
Ranking 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.
RANK () OVER (
[PARTITION BY (col | expr), ...]
[ORDER BY (col | expr), ...]
)
Return Type
An integer
Examples
memsql> create table example (a int, b int);
memsql> insert into example values(1,2),(2,2),(3,3),(4,3);
memsql> select a,b, rank() over(order by b) from example;
+------+------+-------------------------+
| a | b | rank() over(order by b) |
+------+------+-------------------------+
| 1 | 2 | 1 |
| 2 | 2 | 1 |
| 3 | 3 | 3 |
| 4 | 3 | 3 |
+------+------+-------------------------+