Reference > Functions > Aggregate

Min

  • 2005, 2008, 2012, 2014, 2016, 2017, 2019, 2022

Min (Minimum) Aggregate Function

Use the Min function to return the minimum value from a set of values.

Syntax

db.fx.Min({expression})[.Distinct()]

Arguments

expression
The field expression, composite element, or function result to use in finding the minimum value.
Distinct()
Has no functional purpose and is provided for ISO compatibility only.

Returns

The same type as the generic parameter of the provided `expression`.

Examples

Select Statement

Select the minimum of total purchase amount for all purchases.

double minSales = db.SelectOne(
        db.fx.Min(dbo.Purchase.TotalPurchaseAmount)
    )
    .From(dbo.Purchase)
    .Execute();

Order By Clause

Select the minimum of total purchase amount for all purchases ordered by the minimum of total purchase amount descending.

IEnumerable<double> minSales = db.SelectMany(
        db.fx.Min(dbo.Purchase.TotalPurchaseAmount)
    )
    .From(dbo.Purchase)
    .OrderBy(db.fx.Min(dbo.Purchase.TotalPurchaseAmount).Desc())
    .Execute();

Having Clause

Select the minimum of total purchase amount for all purchases (ignoring null values), grouped by payment method type having an minimum greater than 10 and ordered by the minimum of total purchase amount.

IEnumerable<double> minSales = db.SelectMany(
        db.fx.Min(dbo.Purchase.TotalPurchaseAmount)
    )
    .From(dbo.Purchase)
    .GroupBy(dbo.Purchase.PaymentMethodType)
    .Having(db.fx.Min(dbo.Purchase.TotalPurchaseAmount) > 10)
    .OrderBy(db.fx.Min(dbo.Purchase.TotalPurchaseAmount))
    .Execute();
Previous
Max

© 2024 dbExpression. All rights reserved.