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(")"),
  )
)
ParameterTypeRequiredDescription
exprEXPRESSIONYesExpression to count distinct values of
over_clauseOVER CLAUSEYesOVER (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
Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19