I have a table which looks like this:
ID | money_earned | days_since_start |
---|---|---|
1 | 1000 | 1 |
1 | 2000 | 2 |
1 | null | 3 |
1 | 3000 | 4 |
1 | 2000 | 5 |
2 | 1000 | 1 |
2 | null | 2 |
2 | 100 | 3 |
I want that rows, without a value in money_earned (which means that the money_earned column was empty that day) - will and fill the money_earned with last known value, so it to look like this:
ID | money_earned | days_since_start |
---|---|---|
1 | 1000 | 1 |
1 | 2000 | 2 |
1 | 2000 | 3 |
1 | 3000 | 4 |
1 | 2000 | 5 |
2 | 1000 | 1 |
2 | 1000 | 2 |
2 | 100 | 3 |
I have tried to look up for something like that, but postgresql doesn't support ignore nulls in lag window function :(
thank you!