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