在MOODLE中,我使用以下脚本来提取一些数字 - 而且它们很好:
SELECT
qc.name,
q.category,
SUM(IF(qs.grade = "1",1,0)) AS Correct,
SUM(IF(qs.grade = "0",1,0)) AS Wrong
FROM
mdl_question_states qs,
mdl_quiz_attempts qa,
mdl_quiz qz,
mdl_course c,
mdl_question q,
mdl_question_categories qc
WHERE
qa.id = qs.attempt
AND qs.event = 6
AND qa.quiz = qz.id
AND ((qz.name = 'Pre-Test') OR (qz.name = 'Post-Test'))
AND qz.course = c.id
AND q.id = qs.question
AND q.category = qc.id
AND q.category > 601
GROUP BY q.category
ORDER BY qc.name
我的问题是:我想要一个专栏(在'SUM(IF ...'列)之后是'正确-AND-预先测试',然后是'正确-AND-后测试'。
用于完成此任务的语法是什么?
答案 0 :(得分:0)
尝试
SUM(IF(sq.grade = '1' AND qz.name='pre-test', 1, 0)) AS cor_and_pre
和其他值类似。