Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to use a calculated column as an input for the next row?

fieryknight81Oct 9 2019 — edited Oct 11 2019

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:

   

IDDATESCOUNTER
123408/10/20190
123407/10/20190
123406/10/20190
123405/10/20190
123404/10/20190
123403/10/20190
123402/10/20190
123401/10/20190
123430/09/20190
123429/09/20190
123428/09/20190
123427/09/20190
123426/09/20190
123425/09/20190
123424/09/20190
123423/09/20190
123422/09/20190
123421/09/20190
123420/09/20190
123419/09/20190
123418/09/20190
123417/09/20190
123416/09/20190
123415/09/20190
123414/09/201943
123413/09/201943
123412/09/201929
123411/09/201950
123410/09/201928
123409/09/201941
123408/09/201938
123407/09/201944
123406/09/201968
123405/09/201933
123404/09/201951
123403/09/201944
123401/09/201936
123431/08/201949
123430/08/201933
123429/08/201957
123428/08/201965
123427/08/201941
123426/08/201956
123425/08/201928
123424/08/201929
123423/08/201980
123422/08/201976
123421/08/201958
123420/08/201958
123419/08/201956

   

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.

This post has been answered by mathguy on Oct 10 2019
Jump to Answer
Comments
Post Details
Added on Oct 9 2019
3 comments
269 views