製品の将来の在庫の日付と数量をリストするデータセットがあります。時折、私たちの需要は私たちの将来の供給を上回り、私たちは負の将来の量になってしまいます。その将来の負の量を以前の供給に織り込む必要があるので、供給を売り過ぎて問題を悪化させることはありません。
次のデータセットでは、正の数量が残るまでチェーンの上流に負の数量を適用して、10-19の需要に備える必要があります。
"ID","SKU","DATE","SEASON","QUANTITY"
"1","001","2012-06-22","S12","1656"
"2","001","2012-07-13","F12","1986"
"3","001","2012-07-27","F12","-283"
"4","001","2012-08-17","F12","2718"
"5","001","2012-08-31","F12","-4019"
"6","001","2012-09-14","F12","7212"
"7","001","2012-09-21","F12","782"
"8","001","2012-09-28","F12","2073"
"9","001","2012-10-12","F12","1842"
"10","001","2012-10-19","F12","-12159"
私はこれに到達する必要があります:
"ID","SKU","DATE","SEASON","QUANTITY"
"1","001","2012-06-22","S12","1656"
"2","001","2012-07-13","F12","152"
whileループと外部適用を使用することを検討しましたが、これを行う方法をまだ見つけることができないようです。どんな助けでも大歓迎です。これは、SQL Server2008R2で機能する必要があります。
別の例を次に示します。
"1","002","2012-07-13","S12","1980"
"2","002","2012-08-10","F12","-306"
"3","002","2012-09-07","F12","826"
になります:
"1","002","2012-07-13","S12","1674"
"3","002","2012-09-07","F12","826"