APPROX_DISTINCT() OVER ...
All functions > WINDOW FUNCTION > APPROX_DISTINCT() OVER ...
Returns the approximate number of distinct values in the window frame.
Syntax
Diagram(
Sequence(
Terminal("APPROX_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
- Returns approximate count of distinct values using HyperLogLog algorithm
- Much faster than exact COUNT(DISTINCT) for large datasets
- Typical error rate around 2.3%
- Always returns BIGINT type