Use subqueries with HAVING and COUNT(DISTINCT) for cross-category analysis
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.
Each hint you reveal reduces the XP you can earn. Try the query first.
Count distinct categories per customer: `SELECT customer_id FROM fact_purchases WHERE amount > 0 GROUP BY customer_id HAVING COUNT(DISTINCT product_category) >= 3`
That subquery gives you the cross-shoppers. Wrap it to count them: `SELECT COUNT(*) AS multi_category_customers FROM (...) sub`
Make sure the HAVING uses `COUNT(DISTINCT product_category)` — without DISTINCT, multiple purchases in the same category would inflate the count