给定以下结果集:
---------------------------------------------------------
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
---------------------------------------------------------
请注意,NetTotal = SubTotal - Tax
请帮我计算 sum(SubTotal)、sum(Tax) 和 sum(NetTotal),以及旋转的 TransType,如下所示:
--------------------------------------------------------------------------
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
--------------------------------------------------------------------------
如果我只有 1 列要汇总,那么使用 PIVOT 将是直截了当的,但我不确定如何获得 3 个聚合 - 用于 SubTotal、Tax 和 NetTotal。
谢谢你的帮助!