I have a table data
in PostgreSQL with this structure:
created_at. customer_email status
2020-12-31 xxx@gmail.com opened
...
2020-12-24 yyy@gmail.com delivered
2020-12-24 xxx@gmail.com opened
...
2020-12-17 zzz@gmail.com opened
2020-12-10 xxx@gmail.com opened
2020-12-03 hhh@gmail.com enqueued
2020-11-27 xxx@gmail.com opened
...
2020-11-20 rrr@gmail.com opened
2020-11-13 ttt@gmail.com 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?