Table of Contents

Class Count

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

Represents the COUNT aggregate function that returns the number of rows or non-null values.

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

Remarks

The COUNT function counts rows in a group. When used with a column, it counts non-null values. When used without a column (COUNT(*)), it counts all rows including those with null values. This function is commonly used with GROUP BY to count items per group.

Examples

Count the number of orders placed by each customer:

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

var query = new Query()
    .Select([ orders["customer_id"], new Expression("order_count", new Count(orders["id"])) ])
    .From(orders)
    .GroupBy([ orders["customer_id"] ])
    .OrderBy(orders["customer_id"]);

var results = manager.Retrieve(query);

Constructors

Count()

Initializes a new instance of COUNT(*) that counts all rows including nulls.

Count(Column)

Initializes a new instance of COUNT for a specific column, counting non-null values.