Problem like this: table A contain one column number in for recording income, table B contain one column number out for recording outcome.
maybe at an instance, table A records 3,12,3,25,1,3 and table B records 23,1,4. You can consider that I got money 3,12,3,25,1,3 and spent 23,1,4.
Everytime I spends money will take number ordinally 3 first and than 12 util the need is met(3,12,3,25 in this example for 3+12+3+25>23+1+4>3+12+3)
What I want to konw is how can I construct a sql to query what income left? in example above, I shall get 25,1,3 left, yes 25 included also.
// solution in java code level but no elegant
private List<Integer> example(List<Integer> aList, List<Integer> bList){
int sumB = bList.stream().reduce(0, Integer::sum);
List<Integer> res = new ArrayList<>();
int sumA = 0;
for (int a: aList){
sumA = sumA + a;
if (sumA>sumB) res.add(a);
}
return res;
}