Join two tables based on Aggregate Function sum() result
You cannot use SUM in a WHERE clause. However, you can use it in a HAVING

SELECT C.NAME,C.ADDRESS,O.CUSTOMERID
FROM CUSTOMERS C
INNER JOIN
(
    SELECT CUSTOMERID,SUM(ORDERAMOUNT) AS sumorders 
    FROM ORDERS 
    GROUP BY CUSTOMERID 
    HAVING SUM(ORDERAMOUNT)&gt;5000
)O ON C.CUSTOMERID = O.CUSTOMERID;