Class Min
- Namespace
- YndigoBlue.Velocity.Functions
- Assembly
- YndigoBlue.Velocity.dll
Represents the MIN aggregate function that returns the minimum value in a set.
public class Min : Function, ICheckItem, IDefaultItem, IFilterItem, IElement
- Inheritance
-
Min
- Implements
Remarks
The MIN function finds the smallest value in a column, working with numeric, string, and date types. For strings, it returns the first value in alphabetical order. For dates, it returns the earliest date. Null values are ignored. Commonly used with GROUP BY to find the minimum value per group.
Examples
Find the earliest order date per customer:
var schema = manager.LoadSchema("sales");
var orders = schema["orders"];
var query = new Query()
.Select([ orders["customer_id"], new Expression("first_order", new Min(orders["order_date"])) ])
.From(orders)
.GroupBy([ orders["customer_id"] ]);
var results = manager.Retrieve(query);
Find the minimum discounted price using a composed expression (MIN(price * discount_factor)):
var schema = manager.LoadSchema("catalog");
var products = schema["products"];
var query = new Query()
.Select([
products["category"],
new Expression("min_discounted", new Min([ products["price"], new ArithmeticOperator(ArithmeticType.Multiply), products["discount_factor"] ]))
])
.From(products)
.GroupBy([ products["category"] ]);
var results = manager.Retrieve(query);
Constructors
- Min(IEnumerable<IElement>)
Initializes a new instance of MIN for a composed expression (e.g. MIN(ROUND(price, 2))).
- Min(IElement)
Initializes a new instance of MIN for a single element.
- Min(Column)
Initializes a new instance of MIN for a specific column.