argmin
argmin, aggregator
def process argmin(key: number, value: any): any
Returns the item of value
corresponding to the minimum value of key
. If multiple rows have the same minimum key
value, one is chosen arbitrarily.
key
: The number used for ordering.value
: The paired value returned from the corresponding row.
Examples
Basic usage
table T = with
[| as Product, as Price, as Weight |]
[| "Widget A", 100, 2.5 |]
[| "Widget B", 150, 1.8 |]
[| "Widget C", 75, 3.2 |]
cheapestProduct = argmin(T.Price, T.Product)
lightestProduct = argmin(T.Weight, T.Product)
show summary "Product Analysis" with
cheapestProduct as "Cheapest Product"
lightestProduct as "Lightest Product"
This produces:
Cheapest Product | Lightest Product |
---|---|
Widget C | Widget B |
Remarks
When multiple rows share the same T.A
value, argmin
chooses the corresponding T.B
value arbitrarily. Since argmin
works as a sequential scan over the table, reordering the rows may lead to different outputs in cases of ties.