APPROXIMATE_COUNT_DISTINCT
Purpose
This function returns the approximate number of distinct elements (without NULL
).
Syntax
approximate_count_distinct::=
Usage Notes
- The result is not exact as it is with function COUNT, but it can be computed a lot faster.
- For the calculation, the algorithm
HyperLogLog
is used internally.
Example
SELECT COUNT(DISTINCT customer_id) COUNT_EXACT,
APPROXIMATE_COUNT_DISTINCT (customer_id) COUNT_APPR
FROM orders WHERE price > 1000;
Result
COUNT_EXACT | COUNT_APPR |
10000000 | 10143194 |