次のクエリで3つの異なる結果が得られます。これらはすべて同じ結合と列を持ち、カウントする条件が異なります。質問、修正、試行、およびIeslTopics.Name列を一緒に取得できる方法はありますか。単一のクエリ?
SELECT COUNT(TestResults2.QuestionID) AS Questions, Topics.Name
FROM TestResults
INNER JOIN TestResults2 ON TestResults.ID = TestResults2.TestResultID
INNER JOIN QuestionBank ON TestResults2.QuestionID = QuestionBank.ID
INNER JOIN Topics ON QuestionBank.TopicID = Topics.ID
WHERE (TestResults.StudentID = 1) AND (TestResults.ID = 46)
GROUP BY Topics.Name
//All topic
SELECT COUNT(TestResults2.QuestionID) AS Correct, Topics.Name
FROM TestResults
INNER JOIN TestResults2 ON TestResults.ID = TestResults2.TestResultID
INNER JOIN QuestionBank ON TestResults2.QuestionID = QuestionBank.ID AND
TestResults2.Answer = QuestionBank.Answer
INNER JOIN Topics ON QuestionBank.TopicID = Topics.ID
WHERE (TestResults.StudentID = 1) AND (TestResults.ID = 46)
GROUP BY Topics.Name
//Correct topic
SELECT COUNT(TestResults2.QuestionID) AS Attempted, Topics.Name
FROM TestResults
INNER JOIN TestResults2 ON TestResults.ID = TestResults2.TestResultID
INNER JOIN QuestionBank ON TestResults2.QuestionID = QuestionBank.ID AND
TestResults2.Answer <> '\0'
INNER JOIN Topics ON QuestionBank.TopicID = Topics.ID
WHERE (TestResults.StudentID = 1) AND (TestResults.ID = 46)
GROUP BY Topics.Name
//Attempted topic