SELECT `id_user`, SUM(`sum`) `sum`, users.name FROM `balance_history` INNER JOIN `users` ON `id_user` = users.id WHERE balance_history.date >= NOW() - INTERVAL 1 DAY AND `type` = 'plus' GROUP BY `id_user` ORDER BY `sum` DESC LIMIT 5
SELECT
`id_user`,
SUM(IF(`balance_history`.`date` >= NOW() - INTERVAL 1 DAY, `sum`, 0)) `sum_24h`,
SUM(`sum`) `sum_1mnth`,
`users`.`name`
FROM `balance_history`
INNER JOIN `users` ON `id_user` = users.id
WHERE `balance_history`.`date` >= NOW() - INTERVAL 1 MONTH AND `type` = 'plus'
GROUP BY `id_user`
ORDER BY `sum` DESC
LIMIT 5;