Need to group records based on matching reversal in sql
问题 I have a tricky scenario to aggregate the data. Data in my source table is as follows. CustomerId Transaction Type Transaction Amount 1 Payment 100 1 ReversePayment -100 1 payment 100 1 ReversePayment -100 1 Payment 100 1 Payment 100 Requirement is as follows: If the payment as a assoociated Reversepayment with matched amount, sum these two records. If the payment does not have an associated Reverse payment, consider it as orphan(dont sum it). I want output to be like this. CustomerId