I have table (t_answer) like below:
user_id | created_at | answer |
---|---|---|
1 | 2023-01-01 | 1a |
1 | 2023-01-02 | 1b |
1 | 2023-01-11 | 1c |
2 | 2023-02-05 | 2a |
2 | 2023-02-20 | 2a |
I want to retrieve the rows within an interval of 1 week starting from each user’s first answer’s created_at
date. So, the result will be like:
user_id | created_at | answer |
---|---|---|
1 | 2023-01-01 | 1a |
1 | 2023-01-02 | 1b |
2 | 2023-02-05 | 2a |
So, what should be the query to get this?
2
Answers
Using a subquery:
See fiddle.