If I have a table
| Product | date | sold |
|---|---|---|
| A | 2022-01-01 | 2 |
| A | 2022-01-04 | 3 |
| A | 2022-01-06 | 1 |
| B | 2022-01-05 | 4 |
How can I find out the rolling sum of sold for past 4 days for each product in bigquery sql? result looking for:
| Product | date | rolling sum |
|---|---|---|
| A | 2022-01-01 | 2 |
| A | 2022-01-02 | 2 |
| A | 2022-01-03 | 2 |
| A | 2022-01-04 | 5 |
| A | 2022-01-05 | 3 |
| A | 2022-01-06 | 4 |
| B | 2022-01-01 | 0 |
| B | 2022-01-02 | 0 |
| B | 2022-01-03 | 0 |
| B | 2022-01-04 | 0 |
| B | 2022-01-05 | 4 |
| B | 2022-01-06 | 4 |
The major issue is there is no record if there is no product sold.