# rank

relationalai.semantics.std.aggregates

```python
rank(*args: AggValue | Ordering) -> Aggregate
```

Compute rank based on the ordering of values.

## Parameters

- `*args` (`AggValue` | `Ordering`, default: `()`) - Values or Ordering specifications to rank by.

## Returns

- `Aggregate` - An `Aggregate` representing the computation of the rank. Returns `Integer`.

## Examples

Rank employees by salary:

```python
select(Employee, aggregates.rank(aggregates.desc(Employee.salary)))
```

Rank products by price per category:

```python
select(
    Product,
    aggregates.rank(aggregates.asc(Product.price))
    .per(Category)
    .where(Product.category == Category),
)
```

## Referenced By

1. [RelationalAI Documentation](/index.md)1) [Build With RelationalAI](/build/index.md)1. [Use advanced reasoning](/build/reasoning/index.md) / [Rules-based reasoning](/build/reasoning/rules-based/index.md)1) [Aggregate and group data](/build/reasoning/rules-based/aggregate-and-group-data/index.md)1. [Rank groups with `.rank()`](/build/reasoning/rules-based/aggregate-and-group-data/index.md#rank-groups-with-rank)
   2) [Interact with RelationalAI](/interact/index.md)1) [Query a model with PyRel](/interact/query-a-model-with-pyrel/index.md)1. [Rank and select top results with `rank`, `asc`, `desc`, and `top`](/interact/query-a-model-with-pyrel/index.md#rank-and-select-top-results-with-rank-asc-desc-and-top)
   3) [What's new](/release-notes/index.md)1) [Python package and CLI release notes](/release-notes/python/index.md)1. [Python package and CLI 2.1.0](/release-notes/python/2.1.0/index.md)1) [Bug Fixes](/release-notes/python/2.1.0/index.md#bug-fixes)
