sum() of column by distinct() id column
https://tiaashish.wordpress.com/2014/01/31/mysql-sum-for-distinct-rows-with-left-join/

Here is a blog post that describes exactly this situation and provides a very nice solution to it, using a simple formula:

SUM(leads.source_cost) * COUNT(DISTINCT leads.id) / COUNT(*)