Skip to content

top

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

Get the top N results in descending order.

Parameters

  • limit

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

    (AggValue, default: ()) - Values to order by (descending).

Returns

  • Aggregate - An Aggregate representing the computation of the top N results.

Examples

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

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
│               └──  Pick top and bottom results
└──  Release Notes
    └──  Python API Release Notes
        └──  What’s New in Version 1.17.0
            └──  Bug Fixes and Diagnostics