Skip to content

bottom

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

Get the bottom N results in ascending order.

  • limit

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

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

Get 10 lowest-priced products:

>>> select(Product).where(aggregates.bottom(10, Product.price))

Get 5 least selling products per category:

>>> select(Product).where(aggregates.bottom(5, Product.units_sold).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
                └──  Pick top and bottom results