Important
Self-managed SingleStore will soon transition from version 9.1 RC to version 10. This new semantic versioning scheme will provide SingleStore with finer control over engine and feature releases that were not possible with the current versioning scheme.
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 prior to its general availability. Ahead of this transition, SingleStore 9.0 is recommended for production workloads, which can later be upgraded to SingleStore 10.
PERCENT_ RANK
On this page
The PERCENT_ function returns the percent rank of the current row within the partition as specified by the order by clause.
The result is calculated with the following formula: (rank - 1)/(total_
Syntax
PERCENT_RANK () OVER (
[PARTITION BY (col | expr), ...]
[ORDER BY (col | expr), ...]
)Return Type
A DOUBLE data type.
Examples
CREATE TABLE pr_example (a int, b int);INSERT INTO pr_example VALUES(1,2),(2,2),(3,3),(4,3);
SELECT a,b, PERCENT_RANK() OVER(ORDER BY a,b) FROM pr_example;
+------+------+-----------------------------------+
| a | b | percent_rank() over(order by a,b) |
+------+------+-----------------------------------+
| 1 | 2 | 0 |
| 2 | 2 | 0.3333333333333333 |
| 3 | 3 | 0.6666666666666666 |
| 4 | 3 | 1 |
+------+------+-----------------------------------+SELECT a,b, PERCENT_RANK() OVER(ORDER BY b) FROM pr_example;
+------+------+---------------------------------+
| a | b | percent_rank() over(order by b) |
+------+------+---------------------------------+
| 1 | 2 | 0 |
| 2 | 2 | 0 |
| 3 | 3 | 0.6666666666666666 |
| 4 | 3 | 0.6666666666666666 |
+------+------+---------------------------------+Last modified: