SELECT users.*, sum(payments.amount) as `summ`
FROM `users` LEFT OUTER JOIN `payments`
ON `users`.`id` = `payments`.`user_id`
WHERE payments.created_at BETWEEN '$yesterday' and '$today'
AND `status` = '2' GROUP BY user_id
Как добавить 3 таблицу в этот JOIN запрос?
Нужно добавить таблицу qiwi_withdraws тоже объединить её по ID, а затем так же сделать выборку по status=2, created_at, подсчитать и сгруппировать по amount.
SELECT users.*, sum(payments.amount) as `summ`
FROM `users`
LEFT OUTER JOIN `payments`
ON `users`.`id` = `payments`.`user_id`
LEFT OUTER JOIN `qiwi_withdraws`
ON `users`.`id` = `qiwi_withdraws`.`user_id`
WHERE payments.created_at BETWEEN '$yesterday' and '$today'
AND `status` = '2'
GROUP BY user_id