# RANK

Returns the rank of the current row within its partition, with gaps for ties.

`RANK()` assigns the same rank to peer rows that compare equal under the window's `ORDER BY` clause. The next rank then skips ahead by the number of tied rows.

## Signature

```sql
RANK()
```

## Usage Notes

* `RANK()` takes no arguments.
* Ranking restarts for each `PARTITION BY` group.
* The row ranking is determined by the window's `ORDER BY` clause.
* Equal rows receive the same rank, and subsequent ranks contain gaps.
* No explicit window frame clause can be specified for `RANK()`.

## Examples

Rank salespeople by year-to-date sales, leaving gaps when values tie.

```sql
SELECT
    FirstName,
    LastName,
    SalesYTD,
    RANK() OVER (ORDER BY SalesYTD DESC) AS sales_rank
FROM Sales.vSalesPerson;
```

Output:

| FirstName | LastName | SalesYTD   | sales\_rank |
| --------- | -------- | ---------- | ----------- |
| Joe       | Smith    | 2251368.34 | 1           |
| Alice     | Davis    | 2151341.64 | 2           |
| James     | Jones    | 2151341.64 | 2           |
| Dane      | Scott    | 1251358.72 | 4           |

Rank employees within each department by salary.

```sql
SELECT
    department,
    employee_name,
    salary,
    RANK() OVER (
        PARTITION BY department
        ORDER BY salary DESC
    ) AS salary_rank
FROM employees;
```

Output:

| department  | employee\_name | salary | salary\_rank |
| ----------- | -------------- | ------ | ------------ |
| Engineering | Alice          | 160000 | 1            |
| Engineering | Bob            | 150000 | 2            |
| Engineering | Carol          | 150000 | 2            |
| Engineering | Dave           | 140000 | 4            |
| Sales       | Eve            | 130000 | 1            |
| Sales       | Frank          | 120000 | 2            |

## Related Pages

* [Window Functions](/functions/window.md)
* [ROW\_NUMBER](/functions/window/row_number.md)
* [DENSE\_RANK](/functions/window/dense_rank.md)
* [Function Index](/functions/function-index.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.pinot.apache.org/functions/window/rank.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
