-- 
SELECT 
customerid,
SUM(amountposition) AS TotalAmount
FROM Customers
LEFT JOIN PortfolioAmounts
USING(customerid)
GROUP BY customerid;

-- cross check the total amount in Amount Positions Table
SELECT
round(SUM(amountposition),0) / 1000000
FROM PortfolioAmounts;

-- check unmatched records
SELECT 
*
FROM Customers
LEFT JOIN PortfolioAmounts
USING(customerid)
WHERE portfoliopositionsid IS NULL
;