Below is a subset of my table (for the first id)
| date | id | value |
|---|---|---|
| 01/01/2022 | 1 | 5 |
| 08/01/2022 | 1 | 2 |
For each id, the dates are not consecutive (e.g., for id 1, the min date is 01/01/2022 and the max date is 08/01/2022)--there are 7 days in between both dates. I want to insert rows to make the dates for each id consecutive and contiguous - the value for the value field/column to be filled with 0s so that the updated table looks like:
| date | id | value |
|---|---|---|
| 01/01/2022 | 1 | 5 |
| 02/01/2022 | 1 | 0 |
| 03/01/2022 | 1 | 0 |
| 04/01/2022 | 1 | 0 |
| 05/01/2022 | 1 | 0 |
| 06/01/2022 | 1 | 0 |
| 07/01/2022 | 1 | 0 |
| 08/01/2022 | 1 | 2 |
Any SQL code on how to implement this would be highly appreciated. I have a calendar table but am unsure how to join it with the above table so that I fill in missing dates dynamically for each id with 0s.
My calendar table looks like:
| date |
|---|
| 01/01/2022 |
| 02/01/2022 |
| 03/01/2022 |
| 04/01/2022 |