Question:
I’ve got a table that shows me a user_id and the dates they were active (this is derived from a massive events table). The table looks like this:user_id | active_date |
---|---|
1 | 2022-06-16 |
2 | 2022-06-02 |
1 | 2022-06-14 |
1 | 2022-05-01 |
I need to create a query to find if a user has been active in the last 7 days, 8-14 ago, 15-21 days ago, and 22-28 days ago, as well as their first and last active date. I’d like to see the active in the last 7 days column (and the others of that type) as a Boolean if possible.
The first and last active dates are pretty easy, but I need some help with the other dates. This is what I’ve got so far:
Answer:
An approach usingDATE_DIFF
:If you have better answer, please add a comment about this, thank you!