我在以下查询中得到三个不同的结果,它们都有相同的连接和列来计算只是一个条件来计算是不同的,有什么办法可以让我得到 Questions, Correct, Attempted & 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