Problems / Purchase Frequency Distribution / Editorial
GROUP BY customer_id
COUNT(*)
'1'
'2-3'
'4-5'
'6+'
WHEN
Histograms over entities are always double aggregations — one pass to compute each entity's value, one pass to count entities per value range. Trying to do it in a single GROUP BY (GROUP BY customer_id, bucket) can't work: the bucket *depends on* the result of the first aggregation. When a metric's input is itself an aggregate, reach for a CTE and stack the passes.
GROUP BY customer_id, bucket
Solve Purchase Frequency Distribution yourself →