试图合并测试结果,使每个测试都在一行中。我从中提取的数据库每行都有一个答案结果。样本数据:
学生名 | 测试名 | 问题尝试答案正确(0=否,1=是(|
---|---|---|
Mary | 简介评估 | |
Mary | 简介评估 | |
Mary | 简介评估 | |
Joseph | 简介评估 | |
Joseph | 简介评估 | |
Joseph | 简介评估 | |
Tom | 简介评估 | |
Tom | 简介评估 | |
Tom | 简介评估 |
听起来你只想要一个带有一些SUM
的基本GROUP BY
:
SELECT "Student Name", "Test Name"
, SUM("Question Attempt") "Question Attempt"
, SUM("Answered Correctly") "Answered Correctly"
FROM mytable
GROUP BY "Student Name", "Test Name"
GROUP BY "Student Name", "Test Name"
表示您希望每个唯一的学生/测试有一行,SUM
解释了您希望如何组合其他数据。
select student_name, test_name
, count(question_attempt), sum(answered_correctly)
from table
group by student_name, test_name