Hi,
I have a table which has dates, IDs and a counter. ID has a value like 1234 and the counter varies every day. Below is what data looks like:
| ID | DATES | COUNTER |
| 1234 | 08/10/2019 | 0 |
| 1234 | 07/10/2019 | 0 |
| 1234 | 06/10/2019 | 0 |
| 1234 | 05/10/2019 | 0 |
| 1234 | 04/10/2019 | 0 |
| 1234 | 03/10/2019 | 0 |
| 1234 | 02/10/2019 | 0 |
| 1234 | 01/10/2019 | 0 |
| 1234 | 30/09/2019 | 0 |
| 1234 | 29/09/2019 | 0 |
| 1234 | 28/09/2019 | 0 |
| 1234 | 27/09/2019 | 0 |
| 1234 | 26/09/2019 | 0 |
| 1234 | 25/09/2019 | 0 |
| 1234 | 24/09/2019 | 0 |
| 1234 | 23/09/2019 | 0 |
| 1234 | 22/09/2019 | 0 |
| 1234 | 21/09/2019 | 0 |
| 1234 | 20/09/2019 | 0 |
| 1234 | 19/09/2019 | 0 |
| 1234 | 18/09/2019 | 0 |
| 1234 | 17/09/2019 | 0 |
| 1234 | 16/09/2019 | 0 |
| 1234 | 15/09/2019 | 0 |
| 1234 | 14/09/2019 | 43 |
| 1234 | 13/09/2019 | 43 |
| 1234 | 12/09/2019 | 29 |
| 1234 | 11/09/2019 | 50 |
| 1234 | 10/09/2019 | 28 |
| 1234 | 09/09/2019 | 41 |
| 1234 | 08/09/2019 | 38 |
| 1234 | 07/09/2019 | 44 |
| 1234 | 06/09/2019 | 68 |
| 1234 | 05/09/2019 | 33 |
| 1234 | 04/09/2019 | 51 |
| 1234 | 03/09/2019 | 44 |
| 1234 | 01/09/2019 | 36 |
| 1234 | 31/08/2019 | 49 |
| 1234 | 30/08/2019 | 33 |
| 1234 | 29/08/2019 | 57 |
| 1234 | 28/08/2019 | 65 |
| 1234 | 27/08/2019 | 41 |
| 1234 | 26/08/2019 | 56 |
| 1234 | 25/08/2019 | 28 |
| 1234 | 24/08/2019 | 29 |
| 1234 | 23/08/2019 | 80 |
| 1234 | 22/08/2019 | 76 |
| 1234 | 21/08/2019 | 58 |
| 1234 | 20/08/2019 | 58 |
| 1234 | 19/08/2019 | 56 |
Now the issue is the counter is 0 for Sep 15 and i need to replace it with same day previous week value (Sep 8th). In this case its 38.
Same for Sep 16th the value need to be replaced with is from Sep 9th which is 41.
Now when we reach Sep 22nd i need the value of Sep 15th which is already replaced in the previous step, 38. So Sep 22 should display 38.
How can i do this in SQL/PLSQL?
Please help.
Thanks.