I have a table on which some data is missing, so I have to replace the missing data by the data of the day before.
I wanted to do a SQL update to solve this issue.
In case the following criteria is met -> if ID1 is in set(a1,a2,a3) AND TYPE Is MISSING
The variables "Amount" a/b will have an absurd value
We will then take the Amount a/b value of the row of the previous day, where ID1 and ID2 are the same as the one of the row where the criteria is met.
So here ID1 and ID2 are equal to a1 and b1 respectively, we look for a1 and b1 the previous day (10/03/2021) and get the amount 28.45/29.46 that we use to replace the false amount 454848.25/548926.36.
We also copy Type value.
| ID1 | ID2 | Amount a | Amount b | day | Type |
|---|---|---|---|---|---|
| a1 | b1 | 28.45 | 29.46 | 10/03/2021 | Out |
| a2 | b1 | 36.84 | 37.88 | 10/03/2021 | In |
| a1 | b1 | 454848.25 | 548926.36 | 11/03/2021 | /MISSING/ |
Goal:
| ID1 | ID2 | Amount a | Amount b | day | Type |
|---|---|---|---|---|---|
| a1 | b1 | 28.45 | 29.46 | 10/03/2021 | Out |
| a2 | b1 | 36.84 | 37.88 | 10/03/2021 | In |
| a1 | b1 | 28.45 | 29.46 | 11/03/2021 | Out |
My table consists of thousands of rows, but it's the idea
I tried to use lag and SQL update, but did not succeed.
