I have on the datebase a table containing:
- created_at
- order_id
- customer_id
I want to calculate the cumulative distinct number of customers per day.
I wrote this query
SELECT
created_at::date,
COUNT(DISTINCT customer_id) OVER (ORDER BY created_at::date) as cumulative_users
FROM orders
GROUP BY 1
ORDER BY 1
then I figured out that PostgreSQL doesn’t support distinct in a window function.
Can you please help me writing this code?
2
Answers
No windowing function needed here imho.
See SQLFiddle