I have a two table. I want to get the below result out from these two table. Any help appreciate.
EVENT table
event_id | gross_amount | transaction_id
1 | 10 | 1
2 | 12 | 5
TRANSACTION table
trx_id | debit | credit | link_trx_id
1 | 4 | 0 | null
2 | 0 | 2 | 1
3 | 0 | 1 | 2
4 | 3 | 0 | 3
5 | 0 | 5 | null
6 | 0 | 3 | 5
RESULT EXPECTED:
trx_id | debit | credit | current_gross | current_net
1 | 4 | 0 | 10 | 6
2 | 0 | 2 | 6 | 8
3 | 0 | 1 | 8 | 9
4 | 3 | 0 | 9 | 6
5 | 0 | 5 | 10 | 15
6 | 0 | 3 | 15 | 18
Explanation
As you can see transaction 1,2,3,4 falling into an one set while 4,6 falling into an another set. For the each transaction needed the it's linked previous transactions current_net value as a it's current_gross.
Basically getting current_gross is a recursive call. Here I can not use PL SQL function where I can write a quick recursive function to calculate current_gross. I need pure PL/SQL query for this task. ( Can use built in PL SQL functions)