Simple solution: Use two queries.
Otherwise you can do your aggregated calculation in a subquery (on the whole table, not per row) then JOIN the result of the subquery with the addresses table to get your extra data. Try this:
SELECT *
FROM customer T1
LEFT JOIN
(
SELECT custId,
SUM(total) AS sum_total,
COUNT(total) AS count_total
FROM orders
-- WHERE ...
GROUP BY custId
) T2
ON T1.custId = T2.custId
-- WHERE ...
Mark Byers
2010-07-26 09:23:40