Oracle
 sql >> Datenbank >  >> RDS >> Oracle

müssen Datensätze basierend auf übereinstimmenden Stornierungen gruppieren

Ich denke, das ist nur row_number() und Aggregation:

select listagg(row_number, ',') within group (order by row_number) as row_numbers,
       loan_id, txn_entry_api_name, sum(txn_amt) as txn_amt,
       listagg(txn_entry_api_name, ',') within group (order by row_number) as txn_entry_api_name
from (select t.*,
             row_number() over (partition by loan_id, txn_entry_api_name, abs(txn_amt) order by row_number) as seqnum
      from t
     ) t
group by seqnum;