I Join several tables on the principle of left join . And the result is several columns that match for user_id and it turns out that the sum is considered twice.
SELECT s.id AS s__id, s.user_id AS s__user_id, d.account_currency_id AS currency_id, d.platform AS d__2, SUM(d.amount_with_commission) AS sum FROM sf_guard_user_profile s LEFT JOIN sf_guard_user s2 ON s.user_id = s2.id LEFT JOIN user_promo_source u ON s2.id = u.user_id LEFT JOIN user_summary u2 ON s2.id = u2.user_id LEFT JOIN sf_guard_user_profile_accounts s3 ON ( ( s2.id = s3.user_id AND s3.is_remove = 0 ) ) LEFT JOIN deposit_request d ON ( ( d.account_id = s3.id AND ( d.status_id = 5 OR d.status_id = 8 OR d.withdraw_id IS NOT NULL ) ) ) LEFT JOIN sf_guard_user_calls s4 ON s4.user_id = s2.id WHERE ( s.lang = 'en' AND ( u2.start_reg_date >= "2016-09-01 00:00:00" AND u2.start_reg_date <= "2016-09-30 23:59:59" ) AND s4.created_at >= '2016-09-01 00:00:00' AND s.is_test_profile = 0 AND ( NOT (d.amount_with_commission IS NULL) ) ) GROUP BY d.account_currency_id, d.platform ORDER BY d__0 DESC DISTINCT at the beginning of SQL did not help, how to remedy the situation, How to write SQL so that for each user the amount is counted once?
s__idduplicate columns still exist, and the amount will be recalculated for the repeating column. - user216109