I need to use FIFO method (first in first out) and check which Key has not been fully used - so I need to receive the red Keys (can be in seperate table, can be in the original one).
My idea was to create first two tables: one with positive values and second with negative.
Then create some kind of loop that checks if:
-600 + 1000 >= 0 ok
-100 + (1000-600) >=0 ok
-400 + (1000-600-100) >=0 - false, then add to a new Tab2 next positive value = B.
So the result would need to be;
Tab2:
Product
1 B
2 D
2 E
I am not sure if it is the best idea and if it is feasible at all. Any suggestions will be appreciated.