0
$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';
Eric Renouf
  • 13,950
  • 3
  • 45
  • 67
  • What are you trying to do with the query, and what language are you doing it? What about this query is not working? – Eric Renouf May 24 '15 at 02:55
  • Perhaps you'll get some help from this question: http://stackoverflow.com/questions/2722408/how-to-use-count-and-group-by-at-the-same-select-statement – Eric Renouf May 24 '15 at 02:57
  • You don't have any "from tablename" part. – Tim3880 May 24 '15 at 03:13
  • Sorry $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 FROM `itq_exam_thread_test` GROUP BY userid_created ORDER BY sum_result DESC, sum_rate DESC LIMIT 0, 100'; But not run – Quang Chuc Doan May 24 '15 at 05:52

0 Answers0