select CustomerId ,Amount = SUM(Amount) ,InterestAmount = SUM(case when OpType = 1 then Amount else 0 end) ,PrincipalAmount = SUM( case when OpType = 2 then Amount else 0 end) ,TotalCount = Count(0) from