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),
)

Referenced By

RelationalAI Documentation
├──  Build With RelationalAI
│   └──  Understand how PyRel works
│       ├──  Build a semantic model
│       │   └──  Query a model
│       │       └──  Rank and select top results with rank, asc, desc, and top
│       └──  Use advanced reasoning > Rules-based reasoning
│           └──  Aggregate and group data
│               └──  Rank groups with .rank()
└──  Release Notes
    └──  Python API Release Notes
        └──  What’s New in Version 1.18.0
            └──  Bug Fixes