COUNT_DISTINCT() OVER ...
All functions > WINDOW FUNCTION > COUNT_DISTINCT() OVER ...
Returns the count of distinct non-null values in the window frame.
Syntax
Diagram(
Sequence(
Terminal("COUNT_DISTINCT"),
Terminal("("),NonTerminal('expr'),Terminal(")"),
Terminal("OVER"),
Terminal("("),
NonTerminal("over_clause"),
Terminal(")"),
)
)| Parameter | Type | Required | Description |
|---|---|---|---|
expr | EXPRESSION | Yes | Expression to count distinct values of |
over_clause | OVER CLAUSE | Yes | OVER (PARTITION BY ... ORDER BY ... [FRAME ...]) |
Notes
- Counts unique non-null values in the window
- NULL values are excluded from the count
- Always returns BIGINT type
- Use APPROX_DISTINCT for better performance on large datasets