Scenario: Trying to count more active users for time series analysis.
Need: With postgreSQL(redshift) Count customers that have more than X unique transactions within Y days from said date, group by date.
How do i achieve this?
Table: orders
| date | user_id | product_id | transaction_id |
|---|---|---|---|
| 2022-01-01 | 001 | 003 | 001 |
| 2022-01-02 | 002 | 001 | 002 |
| 2022-03-01 | 003 | 001 | 003 |
| 2022-03-01 | 003 | 002 | 003 |
| ... | ... | ... | ... |
Outcome:
| date | active_customers |
|---|---|
| 2022-01-01 | 10 |
| 2022-01-02 | 12 |
| 2022-01-03 | 9 |
| 2022-01-04 | 13 |