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!

cumulative difference with an initial value.

user-7sn79May 5 2023 — edited May 5 2023

Hi All

I need help for a query and my requirement is as below.

qty_needed                    qty_onhand
2                                  5
2                                  5
2                                  5
5                                  5
5                                  5

I want to replace the qty_onhand values with a cumulative difference to avoid repetitive value.

I need a query that will display the cumulative difference for example I have a value say 5 as the initial value of qty_onhand.

formula: qty_onhand - previous qty_needed

Qty_needed             qty_onhand      
2                           5
2                      5 - 2 = 3
2                       3 - 2 = 1
5                       1 - 2 = 0    should be zero because there are no remaining material onhand
5                       0 - 5 = 0
Comments
Post Details
Added on May 5 2023
16 comments
797 views