COUNT_DISTINCT
All functions > AGGREGATE > COUNT_DISTINCT
Returns the number of distinct values in the group.
Syntax
COUNT_DISTINCT(expr, group_by, where)
sql
Arguments
Parameter | Type | Required | Description |
---|---|---|---|
expr | BIGINT | Yes | The expression to count distinct values of |
Returns
The number of distinct non-NULL values
Notes
- Counts unique values in the group
- NULL values are excluded from the count
- Only counts each distinct value once
- Returns 0 for empty groups
- Can be used with WHERE clause to filter before counting
- Can be used with GROUP BY clause for grouped counts