I have a query in a Postgres DB that combines clients subscriptions.
I want to add a variable that's called "consecutive months" but I'm not sure how to do it in Postgres.
My raw table is something like this:
| client | product | Date |
|---|---|---|
| 1 | Sub | 2020-10-01 |
| 1 | Sub | 2020-11-01 |
| 2 | Sub | 2020-11-01 |
| 2 | Sub | 2020-12-01 |
| 1 | Sub | 2021-01-01 |
| 1 | Sub | 2021-02-01 |
| 2 | Sub | 2021-02-01 |
and I inteed to have something that counts the consecutive months originating something like this:
| client | product | Date | Consecutive_months |
|---|---|---|---|
| 1 | Sub | 2020-10-01 | 1 |
| 1 | Sub | 2020-11-01 | 2 |
| 2 | Sub | 2020-11-01 | 1 |
| 2 | Sub | 2020-12-01 | 2 |
| 1 | Sub | 2021-01-01 | 1 |
| 1 | Sub | 2021-02-01 | 2 |
| 2 | Sub | 2021-02-01 | 1 |
Thank you for the help in advanced!