I have a table consisting of inventory data. The first row of the table is correct however for all the other rows, initial inventory should be the final inventory of the previous day and the final inventory should be initial inventory + recieved_sold of that date after having the correct initial inventory for that day . How can I do that in SQL?
Source
initial inventory date received_sold final inventory
20 1/1/23 -1 19
20 1/2/23 0 20
20 1/3/23 4 24
20 1/4/23 2 22
20 1/5/23 -2 18
expected:
initial inventory date received_sold final inventory
20 1/1/23 -1 19
19 1/2/23 0 19
19 1/3/23 4 23
23 1/4/23 2 25
25 1/5/23 -2 23