SELECT * FROM `users` LEFT OUTER JOIN `payments` ON `users`.`id` = `payments`.`user_id` WHERE payments.created_at BETWEEN '2017-05-19 14:23:46' and '2017-06-19 14:23:46' and `status` = 2 GROUP BY 'payments.amount'
SELECT users.*, sum(payments.amount) as `summ`
FROM `users`
LEFT OUTER JOIN `payments` ON `users`.`id` = `payments`.`user_id`
WHERE payments.created_at BETWEEN '2017-05-19 14:23:46' and '2017-06-19 14:23:46'
AND `status` = 2
GROUP BY user.id