Teradata Scenario : Calculate Future Days

General
General covers Articles, Reference documentation, FAQs, Downloads and Blogs that do not belong to a specific subject area. General-purpose Articles about everything and anything
Enthusiast

Teradata Scenario : Calculate Future Days

Hi Experts, 
 
We need your help to implement the following scenario. We have to calculate the number of future days for which demand could be satisfied by the stock on a particular day.
Here is the source data -

Date

Demand

Stock

7/2/2018

20

50

7/3/2018

30

100

7/4/2018

40

..

7/5/2018

50

 ..

7/6/2018

20

.. 
  
The stock of 7/2 (50) is enough to satisfy full demand of 7/3 (30) and half demand of 7/4 (20/40=0.5) . (20 remaining after 30 was consumed on 7/3)  giving days: 1 + 0.5 = 1.5
 
Similarly, the stock of 7/3 is enough to satisfy the full demand of 7/4 (40), full demand of 7/5 (50) and half demand of 7/6 [(100 - (50+40))/20=0.5] giving days = 1+1+0.5 = 2.5
 
Target Data -

Date

Demand

Stock

Number of Days

7/2/2018

20

50

1.5

7/3/2018

30

100

2.5

7/4/2018

40

..

 ..

7/5/2018

50

.. 

 ..

7/6/2018

20

.. 
 
 
Your help would be greatly appritiated.
Thanks