> For the complete documentation index, see [llms.txt](https://docs.pinot.apache.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pinot.apache.org/functions/window/dense_rank.md).

# DENSE\_RANK

This section contains reference documentation for the DENSE\_RANK window function.

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

`DENSE_RANK()` assigns the same rank to peer rows that compare equal under the window's `ORDER BY` clause. The next distinct value gets the next consecutive rank.

## Signature

```sql
DENSE_RANK()
```

## Usage Notes

* `DENSE_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 remain consecutive.
* No explicit window frame clause can be specified for `DENSE_RANK()`.

## Examples

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

```sql
SELECT
    FirstName,
    LastName,
    SalesYTD,
    DENSE_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 | 3           |

Rank employees within each department by salary using consecutive ranks.

```sql
SELECT
    department,
    employee_name,
    salary,
    DENSE_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 | 3            |
| Sales       | Eve            | 130000 | 1            |
| Sales       | Frank          | 120000 | 2            |

## Related Pages

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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 following URL with the `ask` and `goal` query parameters:

```
GET https://docs.pinot.apache.org/functions/window/dense_rank.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `build a script that syncs our docs to a CMS` lets GitBook tailor the answer to that use case.

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.
