$sql = SELECT `id`, `email`, `avatar`,`fullname`,
SUM(result) as sum_result,
SUM(total) as sum_total,
COUNT(rank) as `top_1` where `itq_exam_thread_test`.`rank` = 1,
COUNT(rank) as `top_2` where `itq_exam_thread_test`.`rank` = 2,
COUNT(rank) as `top_3` where `itq_exam_thread_test`.`rank` = 3
GROUP BY userid_created
ORDER BY sum_result DESC, sum_rate DESC
LIMIT 0, 100';