I have a table data
in PostgreSQL with this structure:
created_at. customer_email status
2020-12-31 [email protected] opened
...
2020-12-24 [email protected] delivered
2020-12-24 [email protected] opened
...
2020-12-17 [email protected] opened
2020-12-10 [email protected] opened
2020-12-03 [email protected] enqueued
2020-11-27 [email protected] opened
...
2020-11-20 [email protected] opened
2020-11-13 [email protected] opened
There are many rows for each day.
Basically I need 2021-W01 for this week with the count of unique emails with status "opened" within the last 90 days. Likewise for every week before that.
Desired output:
period active
2021-W01 1539
2020-W53 1480
2020-W52 1630
2020-W51 1820
2020-W50 1910
2020-W49 1890
2020-W48 2000
How can I do that?