Given the following result set:
---------------------------------------------------------
CustomerID Service TransType SubTotal Tax NetTotal
---------------------------------------------------------
106 A CREDIT 12.52 - 12.52
106 A CREDIT 10.07 - 10.07
106 B CREDIT 2.00 - 2.00
106 C REMOTE 5.99 - 5.99
106 C CREDIT 5.99 - 5.99
106 C CREDIT 3.99 0.30 3.69
106 C CREDIT 5.99 0.30 5.69
106 D CREDIT 5.99 - 5.99
---------------------------------------------------------
Note that NetTotal = SubTotal - Tax
Please help me calculate sum(SubTotal), sum(Tax) and sum(NetTotal), along with pivotted TransType, as follows:
--------------------------------------------------------------------------
CustomerID Service Cash Check Credit Remote SubTotal Tax NetTotal
--------------------------------------------------------------------------
106 A 0 0 22.59 0 22.59 0 22.59
106 B 0 0 2.00 0 2.00 0 2.00
106 C 0 0 15.97 5.99 21.96 0.60 21.36
106 D 0 0 5.99 0 5.99 0 5.99
--------------------------------------------------------------------------
If I had only 1 column to be summarized it would be straight forward using PIVOT, but I am not sure how to get the 3 aggregates - for SubTotal, Tax and NetTotal.
Thanks for your help!