Table of Contents

Class Sum

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

Represents the SUM aggregate function that calculates the total of numeric values.

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

Remarks

The SUM function adds up all non-null numeric values in a column or expression. The argument can be a single column or a composed arithmetic expression such as SUM(price * quantity). Null values are ignored in the calculation. Commonly used with GROUP BY to calculate subtotals per group, but also valid without GROUP BY to aggregate across the entire result set.

Examples

Calculate total revenue per product category:

var schema = manager.LoadSchema("sales");
var orders = schema["orders"];

var query = new Query()
    .Select([ orders["category"], new Expression("total_revenue", new Sum(orders["amount"])) ])
    .From(orders)
    .GroupBy([ orders["category"] ]);

var results = manager.Retrieve(query);

Sum a composed expression (SUM(price * quantity)):

var schema = manager.LoadSchema("sales");
var orders = schema["orders"];

var query = new Query()
    .Select([
        orders["customer_id"],
        new Expression("total_value", new Sum([ orders["price"], new ArithmeticOperator(ArithmeticType.Multiply), orders["quantity"] ]))
    ])
    .From(orders)
    .GroupBy([ orders["customer_id"] ]);

var results = manager.Retrieve(query);

Constructors

Sum(IEnumerable<IElement>)

Initializes a new instance of SUM for multiple elements (for arithmetic expressions).

Sum(IElement)

Initializes a new instance of SUM for a single element.

Sum(Column)

Initializes a new instance of SUM for a column.