0

在 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- Pre-Test”,然后是“Correct -AND- Post-Test”。

用于完成此操作的语法是什么?

4

1 回答 1

0

尝试

SUM(IF(sq.grade = '1' AND qz.name='pre-test', 1, 0)) AS cor_and_pre

对于其他值也是如此。

于 2013-01-18T16:16:27.300 回答