请参阅表:http://dl.dropbox.com/u/10356431/Shared/screen.png
请帮助我构建一个SQL,以便在针对特定test_id的在线考试中找到正确回答的问题。
我已经构建了一个。
SELECT COUNT(UNIQUE d.question_id) AS CORRECT
FROM test_response d,
question_response r
WHERE d.response_id = r.question_resp_id
AND r.correct_response_flag != 'N'
AND d.test_id = '10113'但问题是,虽然它可以准确地找到单项选择题,但如果它是一个多项选择题,假设4个回答中的2个是正确的,那么选择一个将被视为正确回答的问题,这是不准确的。
逻辑:生成问题集并显示给用户。每个测试都有自己的id,使用一个特定的问题集。用户选择的响应存储在test_response表中。
发布于 2012-04-23 15:25:59
UPDATE:这不适用于OP的表设计,即为4答案问题创建2行
我认为你需要首先检查每个问题是否所有答案都正确,然后计算没有错误答案的问题:
select
count(*) - count(incorrect_answers_per_question) correct
from (
select
d.test_id,
d.question_id,
sum(case when r.correct_response_flag = 'N' then 1 end) incorrect_answers_per_question
from test_response d
join question_response r on d.response_id = r.question_resp_id
where d.test_id = '10113'
group by d.test_id, d.question_id
)https://stackoverflow.com/questions/10275826
复制相似问题