Skip to content

rank

relationalai.semantics.std.aggregates
rank(*args: AggValue | Ordering) -> Aggregate

Compute rank based on the ordering of values.

  • *args

    (AggValue | Ordering, default: ()) - Values or Ordering specifications to rank by.
  • Aggregate - An Aggregate representing the computation of the rank. Returns Integer.

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