dongmi5015 2014-06-15 10:11
浏览 25

在数百名申请人中获取前3名记录

i am developing an online test system in php,mysql..when a student submits a test its marks are calculated on the basis of correct answers matched from database using following query..

SELECT qa.question_id, qa.test_id, uta.user_answer,uta.user_id,  qa.type,
   qa.answers correct_answer,
 CASE WHEN uta.user_answer = qa.answers THEN 'correct' ELSE 'incorrect' END
 AS count(status)
 FROM questions_answer qa
 LEFT JOIN 
  (
  SELECT user_id, type, test_id, question_id,
  GROUP_CONCAT(answers ORDER BY answers) AS user_answer,
  timestamp from user_test_answers
  WHERE  test_id = '1'    
 GROUP BY user_id, question_id
  ) uta
 ON qa.question_id = uta.question_id
 where qa.test_id=1 GROUP BY uta.user_id

my problem is: I want to count the no of times "correct" appear in field STATUS field in table... these no of correct answers are passed as an argument in a function.... i cant get results of other students....so i want to compare on the basis of CORRECT string appearing in field on the basis of user_id and display top 3 scorers.. How to do this "top 3 scorers in a particular test"..

I am a newbie to MySQL..

  • 写回答

1条回答 默认 最新

  • dongtangdao7232 2014-06-15 12:20
    关注

    If I had to guess, the following should give you what you want. Change:

     CASE WHEN uta.user_answer = qa.answers THEN 'correct' ELSE 'incorrect' END AS count(status)
    

    to

    sum(uta.user_answer = qa.answers) as NumCorrect
    
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀