Table of Contents

Class Max

Namespace
YndigoBlue.Velocity.Functions
Assembly
YndigoBlue.Velocity.dll

Represents the MAX aggregate function that returns the maximum value in a set.

public class Max : Function, ICheckItem, IDefaultItem, IFilterItem, IElement
Inheritance
Max
Implements

Remarks

The MAX function finds the largest value in a column, working with numeric, string, and date types. For strings, it returns the last value in alphabetical order. For dates, it returns the latest date. Null values are ignored. Commonly used with GROUP BY to find the maximum value per group.

Examples

Find the highest-priced product in each category:

var schema = manager.LoadSchema("catalog");
var products = schema["products"];

var query = new Query()
    .Select([ products["category"], new Expression("max_price", new Max(products["price"])) ])
    .From(products)
    .GroupBy([ products["category"] ]);

var results = manager.Retrieve(query);

Find the maximum discounted price using a composed expression (MAX(price * discount_factor)):

var schema = manager.LoadSchema("catalog");
var products = schema["products"];

var query = new Query()
    .Select([
        products["category"],
        new Expression("max_discounted", new Max([ products["price"], new ArithmeticOperator(ArithmeticType.Multiply), products["discount_factor"] ]))
    ])
    .From(products)
    .GroupBy([ products["category"] ]);

var results = manager.Retrieve(query);

Constructors

Max(IEnumerable<IElement>)

Initializes a new instance of MAX for a composed expression (e.g. MAX(ROUND(price, 2))).

Max(IElement)

Initializes a new instance of MAX for a single element.

Max(Column)

Initializes a new instance of MAX for a specific column.