Skip to content

rank

relationalai.semantics.std.aggregates
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:

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

Rank products by price per category:

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