Problem Statement
How do you count unique paying customers per month?
Explanation
COUNT(DISTINCT col) deduplicates values before counting. It is ideal when multiple rows per customer exist.
If you also group by month, you get unique customers per month.
Code Solution
SolutionRead Only
SELECT date_trunc('month', paid_at) AS mon,
COUNT(DISTINCT customer_id) AS unique_buyers
FROM payments
GROUP BY date_trunc('month', paid_at);Practice Sets
This question appears in the following practice sets:
