Category: Aggregation

APPROX_COUNT_DISTINCT

APPROX_COUNT_DISTINCT counts the distinct values of a column approximately and is faster than COUNT(DISTINCT) on large data.

Syntax

APPROX_COUNT_DISTINCT(column_name)

AMC specifics

  • Null values are not counted. The price of the speed is a small error in the result.
  • For reach over user_id, COUNT(DISTINCT user_id) remains the documented form: for columns with the very high threshold Amazon names only COUNT and COUNT DISTINCT as permitted aggregations. Whether APPROX_COUNT_DISTINCT is allowed on user_id is not stated there.

Example

Approximate number of distinct creatives per campaign.

SELECT
  campaign,
  APPROX_COUNT_DISTINCT(creative_id) AS approx_creatives
FROM
  dsp_impressions
GROUP BY
  1

Checked against the AMC schema, not executed on an AMC instance.

Related functions: COLLECT, PERCENTILE

Source: advertising.amazon.com (retrieved 2026-10-09)