我有一個包含日期和事務的表。我需要計算運行總數(除非需要在「數量」中存在負值時重置爲零,然後再次開始計算運行總數,否則使用總分區將會很容易)。有任何想法嗎?SQL運行總計並重置
account|amount| date |total| 123456 |50 |2017-01-01 00:00:00|50 123456 |50 |2017-01-02 00:00:00|100 123456 |100 |2017-01-03 00:00:00|200 123456 |-50 |2017-01-04 00:00:00|0 123456 |100 |2017-01-05 00:00:00|100 123456 |100 |2017-01-06 00:00:00|200
你見過https://stackoverflow.com/questions/22235959/window-functions-running-total-with-reset?rq=1 –
沒有,他說他想從0重新啓動的總和,如果遇到負數的行 –