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.
ROW_ NUMBER
On this page
The ROW_ function returns the number of the current row within its partition.
Syntax
ROW_NUMBER () OVER (
[PARTITION BY (col | expr), ...]
[ORDER BY (col | expr), ...]
)Return Type
An integer
Examples
CREATE TABLE rownum_example (a int, b int);INSERT INTO rownum_example VALUES(1,2),(2,2),(3,3),(4,3);
SELECT a,b, ROW_NUMBER() OVER() FROM rownum_example;
+------+------+---------------------+
| a | b | ROW_NUMBER() OVER() |
+------+------+---------------------+
| 3 | 3 | 1 |
| 4 | 3 | 2 |
| 2 | 2 | 3 |
| 1 | 2 | 4 |
+------+------+---------------------+SELECT a,b, ROW_NUMBER() OVER(PARTITION BY b ORDER BY a DESC) FROM rownum_example;
+------+------+---------------------------------------------------+
| a | b | row_number() over(partition by b order by a desc) |
+------+------+---------------------------------------------------+
| 2 | 2 | 1 |
| 1 | 2 | 2 |
| 4 | 3 | 1 |
| 3 | 3 | 2 |
+------+------+---------------------------------------------------+Last modified: