# PERCENT\_RANK

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_rows - 1)`

## Syntax

```
PERCENT_RANK () OVER (
    [PARTITION BY (col | expr), ...] 
    [ORDER BY (col | expr), ...]
)

```

## Return Type

A `DOUBLE` data type.

## Examples

```sql
CREATE TABLE pr_example (a int, b int);

INSERT INTO pr_example VALUES(1,2),(2,2),(3,3),(4,3);

```

```sql
SELECT a,b, PERCENT_RANK() OVER(ORDER BY a,b) FROM pr_example;

```

```output

+------+------+-----------------------------------+
| a    | b    | percent_rank() over(order by a,b) |
+------+------+-----------------------------------+
|    1 |    2 |                                 0 |
|    2 |    2 |                0.3333333333333333 |
|    3 |    3 |                0.6666666666666666 |
|    4 |    3 |                                 1 |
+------+------+-----------------------------------+
```

```sql
SELECT a,b, PERCENT_RANK() OVER(ORDER BY b) FROM pr_example;

```

```output

+------+------+---------------------------------+
| a    | b    | percent_rank() over(order by b) |
+------+------+---------------------------------+
|    1 |    2 |                               0 |
|    2 |    2 |                               0 |
|    3 |    3 |              0.6666666666666666 |
|    4 |    3 |              0.6666666666666666 |
+------+------+---------------------------------+
```

***

Modified at: February 16, 2023

Source: [/db/v9.1/reference/sql-reference/window-functions/percent-rank/](https://docs.singlestore.com/db/v9.1/reference/sql-reference/window-functions/percent-rank/)

(An index of the documentation is available at /llms.txt)
