Skip to content

top

relationalai.semantics.std.aggregates
top(limit: int, *args: AggValue) -> Aggregate

Get the top N results in descending order.

  • limit

    (int) - Number of top results to return.
  • *args

    (AggValue, default: ()) - Values to order by (descending).
  • Aggregate - An Aggregate representing the computation of the top N results.

Get top 10 highest-paid employees:

>>> select(Employee).where(aggregates.top(10, Employee.salary))

Get top 3 products by revenue per store:

>>> select(Product).where(aggregates.top(3, Product.revenue).per(Store).where(Product.store == Store))
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
                └──  Pick top and bottom results