I am trying to fetch a SUM() for each user in a table, but MySQL is returning the wrong values.
This is how it should look (http://sqlfiddle.com/#!2/7b988/4/0)
This is a old post , but i think this can help others
use distinct inside sum
SELECT
blocks.user_id,
SUM(distinct payout_history.amount) as amount
FROM blocks
LEFT JOIN payout_history
ON blocks.user_id = payout_history.user_id
WHERE confirms > 520
GROUP BY blocks.user_id
Refer this answer by @jerome wagner
MYSQL sum() for distinct rows