Marketing Analytics Path · Mission 23 of 25Expert

Customers buying across categories

Use subqueries with HAVING and COUNT(DISTINCT) for cross-category analysis

Back to Marketing Analytics

The Brief

Marcus BellHead of Growthanalytics-help

How many customers have purchased from 3 or more different product categories? These are our cross-shoppers — the most valuable segment. Just give me the count. Exclude refunds.

You'll practice

COUNT DISTINCTSubqueries

Tables available

fact_purchases

Hints (3)

Each hint you reveal reduces the XP you can earn. Try the query first.

Hint 1

Count distinct categories per customer: `SELECT customer_id FROM fact_purchases WHERE amount > 0 GROUP BY customer_id HAVING COUNT(DISTINCT product_category) >= 3`

Hint 2

That subquery gives you the cross-shoppers. Wrap it to count them: `SELECT COUNT(*) AS multi_category_customers FROM (...) sub`

Hint 3

Make sure the HAVING uses `COUNT(DISTINCT product_category)` — without DISTINCT, multiple purchases in the same category would inflate the count