用于计算答案的SQL查询

时间:2013-01-31 20:24:41

标签: sql ms-access

这是我的困境。我正在研究一个数据库,该数据库将采用学生的答题纸,放入表[答案]并将其与表[测试]中的答案键进行比较。此外,与每个问题相关的是特定的教育标准。

我从测试网站获得了一份excel导出的答案。它的设置如下:

| Student ID | Student | Ans 1 | Ans 2 | Ans 3 | etc... |

所以[Answers]设置为从Excel直接导入。

最终结果是学生错过的标准清单。即:

| Name     | Standard | Count |
| John Doe | ABC1234  |   8   |

我对如何达到这一点感到茫然。我可以错过标准,但我不能横向计算。

非常感谢任何帮助。感谢。

1 个答案:

答案 0 :(得分:3)

您需要使用UNION ALL查询取消表格中的数据:

select [student id], [student], [Ans 1] As Answer
from yourtable
union all
select [student id], [student], [Ans 2] As Answer
from yourtable
union all
select [student id], [student], [Ans 3] As Answer
from yourtable
union all
select [student id], [student], [Ans 4] As Answer
from yourtable

一旦数据在一列中,您就可以应用count()