I have below Scenario where Derived Column 1 and Derived Column 2 are expected Output.(rest are all in same table)
For Each Debit need to check if Credit is able to satisfy that value if not, it will satisfy the partial transaction got to next for rest of the amount(Shown in Trans_id=101)
Similarly if Credit is higher and able to satisfy the debit it will go to next debit for transaction(Shown in Trans_id=102)
Total of Credit -debit will always be zero.
Normally each transaction have only 2 record of credit and debit but few cases there are multiple which need to be handled
Looking to write it in SQL Query.I understand that it might be possible in stored procedure or function but cannot use it due to some constraints
I understand its a looping concept and can be done in procedural language but if any one can give any idea to do it in SQL
Attached is the Screen shot of the Scenarios and below as well