I have an annual amount for each subscription with start_date
structure;
userid startDate(dd-mm-yyyy) amount
1 01-10-2020 120
1 01-10-2021 240
2 01-08-2020 60
I want to divide annual amount to months equally.
Output table should be like;
userid startDate(dd-mm-yyyy) amount
1 01-10-2020 10
1 01-11-2020 10
1 01-12-2020 10
1 01-01-2021 10
1 01-02-2021 10
1 01-03-2021 10
1 01-04-2021 10
1 01-05-2021 10
1 01-06-2021 10
1 01-07-2021 10
1 01-08-2021 10
1 01-09-2021 10
1 01-10-2021 20
1 01-11-2021 20
1 01-12-2020 20
1 01-01-2021 20
1 01-02-2021 20
1 01-03-2021 20
1 01-04-2021 20
1 01-05-2021 20
1 01-06-2021 20
1 01-07-2021 20
1 01-08-2021 20
1 01-09-2021 20
2 01-08-2020 5
2 01-09-2020 5
2 01-10-2020 5
2 01-11-2020 5
2 01-12-2020 5
2 01-01-2021 5
2 01-02-2021 5
2 01-03-2021 5
2 01-04-2021 5
2 01-05-2021 5
2 01-06-2021 5
2 01-07-2021 5
Where should I start, how can I achieve this on postgresql?
2
Answers
Fiddle
Another approach, you may try a recursive query as the following:
See a demo.