In Amazon Athena I have a table that looks like this:
id amount date
1 100 2018-04-05
1 50 2018-06-18
2 10 2018-04-23
2 100 2018-04-28
2 50 2018-07-07
2 10 2018-08-08
And I would like a result such as
id cum_sum date
1 100 2018-04
1 100 2018-05
1 150 2018-06
1 150 2018-07
1 150 2018-08
2 110 2018-04
2 110 2018-05
2 110 2018-06
2 160 2018-07
2 170 2018-08
So I would like to have the cumulative sum per ID per end of month (last day of month). I know how to do it month by month, but not in one query.
Another problem also becomes filling in the empty months (i.e. ID 1 does not have entries for all months, so the cumulative sum just has to reused).
If there's a solution for MySQL as well, I'd appreciate it too.
I hope this makes sense, and thanks in advance.