Cumalative Sum and Supply/Demand Delay
-
Hi, I have a table consisting of the following columns of relevance: Day - Integer ranging from 1-9 Demand_Qty - Double value specifying the demand for that particular day. Demand_Filled - Doulbe value specifying how much of the item was recieved that day. What I need to find out is how many days it takes before each demand is filled. For example: Day Demand_Qty Demand_Filled Days_to_Fill 1 10 0 2 2 10 0 2 3 20 10 1 4 5 30 1 5 10 10 -1 The first 3 columns are provided and the Days_to_Fill column is what I need to calculate. A -1 in the Days_To_Fill means the demand was never met. As you can see, the Demand for Day 1 is 10, which is not filled until Day 3. If further clarification is needed, pls inquire. I'm not sure exactly where to begin so any tips/ideas/solutions would be greatly appreciated. One thing that I believe could get me closer to a solution would be acquiring a cumalative sum of Demand_Qty and Demand_Filled for each day, but I don't know how to do this in SQL... anyone know how? What I mean is a sum that would look like this based on the above sample: Day SumDemand SumFilled 1 10 0 2 20 0 3 40 10 4 45 40 5 55 50 Thank you for any help in advance, hoping I can get a solution figured out soon for my Project Manager. -Tom