如何在 MySQL 中按两列比较两个查询?
按两列比较两个查询的最佳方法是什么?这些是我的表格:
此表显示考试问题
idEvaluation | Question | AllowMChoice | CorrectAnswer|
1 1 0 3
1 2 1 4
1 2 1 5
1 3 0 9
此表显示已完成的考试
idExam| idEvaluation | Question | ChosenAnswer|
25 1 1 2
25 1 2 4
25 1 2 5
25 1 3 8
我必须计算正确答案的百分比,考虑到某些问题可能允许多项选择。
正确答案/总答案 * 100
感谢您的提示!
What's the best way to compare two queries by two columns? these are my tables:
This table shows exam questions
idEvaluation | Question | AllowMChoice | CorrectAnswer|
1 1 0 3
1 2 1 4
1 2 1 5
1 3 0 9
This table shows a completed exam
idExam| idEvaluation | Question | ChosenAnswer|
25 1 1 2
25 1 2 4
25 1 2 5
25 1 3 8
I have to calculate the percentage of correct Answers, considering to certain questions may allow multiple selection.
Correct Answers / Total Answers * 100
thanks for your tips!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此代码将向您显示问题列表以及是否正确回答了这些问题。
已确认输出:
注意,这些列有意以这种方式命名,因为它们将作为子查询包含在内在下面的第 2 部分中。
此代码将为您提供测试分数。
输出已确认:
这将传达一般概念。您的列名称
idEvaluation
和Eval
对我来说很难理解,但我确信您可以调整上面的代码以适合您的目的。请注意,我在 sql server 中执行此操作,但我使用了相当基本的 SQL 功能,因此它应该可以很好地转换为 MySQL。
This code will show you a listing of Questions and whether or not they were answered correctly.
Output Confirmed:
Note, the columns are intentionally named this way, as they are to be included as a subquery in part-2 below.
This code will give you the test score.
Output Confirmed:
This will communicate the general concept. Your column names
idEvaluation
andEval
are difficult for me to understand, but I'm sure you can adjust the code above to suit your purposes.Note, I did this in sql server, but I used fairly basic SQL functionality, so it should translate to MySQL well.