SQL Cumulative recursive sum (Backtracking)