I am trying to create a 3 month lookahead type table. So for example any event where LAST_DAY(event_date) = '2021-01-01' (i.e Jan-2021) will be valid in February-2021 and March-2021 as well.
For each event, I want another row for the 2 months after which it happens. Example below:
Given data that looks like this:
| event_date | customer_id |
|---|---|
| Jan-21 | A |
| Feb-21 | B |
| Jan-21 | A |
| Jun-21 | C |
| Mar-21 | D |
I want to create some thing that looks like this:
| event_date | customer_id |
|---|---|
| Jan-21 | A |
| Feb-21 | A |
| Mar-21 | A |
| Feb-21 | B |
| Mar-21 | B |
| Apr-21 | B |
| Jun-21 | C |
| Jul-21 | C |
| Aug-21 | C |
| Mar-21 | D |
| Apr-21 | D |
| May-21 | D |
Kind of stuck on how to achieve this. You can assume that the event_date is a valid datetime field here. I've tried a few different things to no avail. I would usually use a window function for something like this with PRECEDING and FOLLOWING limits here but LEAD, LAG type functions only allow you to set 1 offset and not a range of offset.
Any help is appreciated. Working in PSQL.
