Table of Contents

Class CountDistinct

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

Represents the COUNT(DISTINCT) aggregate function that returns the number of unique non-null values.

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

Remarks

The COUNT DISTINCT function counts unique values in a column, excluding duplicates and null values. This is useful for determining the number of distinct categories, unique identifiers, or different values in a dataset. Often used with GROUP BY to count distinct items per group.

Examples

Count the number of distinct products ordered per customer:

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

var query = new Query()
    .Select([ orders["customer_id"], new Expression("unique_products", new CountDistinct(orders["product_id"])) ])
    .From(orders)
    .GroupBy([ orders["customer_id"] ]);

var results = manager.Retrieve(query);

Constructors

CountDistinct(Column)

Initializes a new instance of COUNT(DISTINCT) for a specific column.