-- What is the total amount in active positions of customers of each Account Manager?
-- TIPS:
-- first can try to join each pair of tables separately, undersand how the records are repeated? 
-- we can find the records without a match by using WHERE clause targetting NULL values
-- inspect the row output before grouping
-- the last joined table in the chain has the records that are not repeated.

SELECT
	am.accountmanagerid,
    am.AccountManager,
	ROUND(SUM(pa.amountposition),2) AS TotalAmountPosition
FROM AccountManagers AS am
LEFT JOIN Customers AS c
	ON am.accountmanagerid = c.accountmanagerid
LEFT JOIN PortfolioAmounts  AS pa
	ON c.customerid = pa.customerid
GROUP BY 
	am.accountmanagerid, 
	am.AccountManager
;

SELECT *
FROM AccountManagers AS am
LEFT JOIN Customers AS c
	ON am.accountmanagerid = c.accountmanagerid
LEFT JOIN PortfolioAmounts  AS pa
	ON c.customerid = pa.customerid

