I have a problem involving a SUM, LEFT OUTER JOIN and GROUP BY commands, but can\'t figure out where my error is.
I have two tables, one for customer transactions an
With T as (
SELECT Customer,
[Transaction Year],
sum(Amount) AS TransactionAmount
FROM Transactions
GROUP BY Customer, [Transaction Year]
), C AS
SELECT Customer,
[Claim Year],
sum(Amount) as ClaimAmount
FROM Claims
GROUP BY Customer, [Claim Year]
)
SELECT T.Customer,
[Transactions Year],
TransactionAmount,
ClaimAmount
FROM T
LEFT JOIN C ON C.Customer = T.Customer
AND [Transactions Year] = [Claim Year]