gpt4 book ai didi

mysql - 考试总答对(建表mysql)

转载 作者:行者123 更新时间:2023-11-29 05:09:12 25 4
gpt4 key购买 nike

你好,我想创建一个 View 表来计算每个用户的正确答案。我的表的架构是这样的。

用户考试表

user_id     | questionnaire_id | answer_id
1 | 1 | 3
1 | 2 | 1
2 | 1 | 4
2 | 2 | 2

答案表

answer_id   questionnaire_id    is_correct
1 1 1
2 1 0
3 1 0
4 1 0
1 2 0
2 2 1
3 2 0
4 2 0

谢谢

最佳答案

因为is_correct的值为1,所以可以求和得出他们的总分:

select e.user_id, sum(a.is_correct) score
from exam_table e
left join answer_table a
on a.questionnaire_id = e.questionnaire_id
and a.answer_id = e.answer_id
group by e.user_id;

Here is a functional example与一个满分的新用户

关于mysql - 考试总答对(建表mysql),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42511819/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com