SET @i=0;
SELECT @i:=@i+1 AS `rank`, count(`t1`.`id`) AS `referals`
FROM `tb_users`
LEFT JOIN `tb_users` `t1` ON `t1`.`referer` = `tb_users`.`username`
GROUP BY `tb_users`.`id`
HAVING `referals` >= 895
ORDER BY `referals` DESC, `tb_users`.`id` ASC