I need to add two different fields in two separate tables, but the second sum is double what it should be. Here's what I'm using:
Select A.dc,A.rc,B.acctno,
((Sum(If(B.ttc In ('X','Y','Z'), 0, B.ua))) -
(Sum(If(B.ttc In ('X','Y','Z'), B.ua, 0)))) As Total_UA,
(Sum(C.cub)) As Total_CUB
From Table_B As B
Left Join Table_C As C On B.acctno = C.acctno
Left Join Table_A As A On B.acctno = A.acctno
Where A.status != 'C'
Group By B.acctno Having Abs(Total_UA - Total_CUB) > 0.0001
Total_UA is coming out fine, but Total_CUB is double what it should be. Any help would be much appreciated as to what I'm doing wrong or if there is a better way of doing this.