I would like to keep a running/cumulative array of new IDs.
Starting with this:
Date | IDs_Used_Today | New_IDs |
---|---|---|
Dec 6 | 1, 2, 3 | 1, 2, 3 |
Dec 7 | 1, 4 | 4 |
Dec 8 | 2, 3, 4 | 3 |
Dec 9 | 1, 2, 3, 5 | 5 |
And getting this:
Date | IDs_Used_Today | New_IDs | All_IDs_To_Date |
---|---|---|---|
Dec 6 | 1, 2, 3 | 1, 2, 3 | 1, 2, 3 |
Dec 7 | 1, 4 | 4 | 1, 2, 3, 4 |
Dec 8 | 2, 3, 4 | null | 1, 2, 3, 4 |
Dec 9 | 1, 2, 3, 5 | 5 | 1, 2, 3, 4, 5 |
I need to do this by getting the values for "All_IDs_To_Date" from previous "All_IDs_To_Date" + "New_IDs"
by doing it that way, the table will always be accurate as long as there is one previous row of data.
So basically a combination of CONCAT( LAG(All_IDs_To_Date), New_IDs) with an IF conditional when there is no LAG(ALL_IDs_To_Date) then use that date's "New_IDs" value.
It is very important that if old rows are deleted, the most current rows keep the same data. Meaning if I start with 10 rows stored, with the last running total being "1,2,3,4,5" and then I delete the first 9 rows. My next calculation would be based off that last stored row, so my running total would still be adding to the "1,2,3,4,5" that was previously stored.