I have an event table that looks like this.
| id | event_id| date |
|----|---------|------------|
| 1 | d-paiin | 28/01/2022 |
| 1 | 123gin | 02/01/2022 |
| 1 | dhsdel | 01/01/2022 |
| 1 | sigshwy | 31/12/2021 |
| 1 | dsiwuef | 31/12/2021 |
| 2 | shau346 | 10/02/2022 |
| 2 | akdnjsfm| 04/02/2022 |
| 2 | asjufbe | 04/02/2022 |
| 2 | jladiurn| 01/02/2022 |
I want to write a query that finds id and their number of events in the last 30days using the MAX Date of each user as a reference point. i.e count of event per id where date > (MAX(Date) of each user) - 30 days.
Expected result looks like this:
| id | count_event|
| 1 | 5 |
| 2 | 4 |
Thanks.