首先,我安排了一个特定模块的考试。模块包含超过2-3章,每章包含50-60个不同标记的问题。现在问题在于从所有章节中检索问题,并且应该完全相同,没有问题,并且标记总和应该与在考试预定时间保存的相同。
table [Module](
[module_id]
[module_name]
)
table [Chapter](
[chapter_id]
[module_id]
[chapter_name]
)
question_bank table
[question_id] [chapter_name] [question_text] [Marks]
10001 .NET Question1 1
10002 .NET Question2 2
10003 .NET Question3 4
10004 .NET Question4 1
10005 .NET Question5 1
10006 .NET Question6 4
10007 .NET Question7 1
10008 .NET Question8 2
10009 .NET Question9 1
exam_schedule table
[exam_id] [module_id] [question] [total_marks]
1001 1001 6 10
Output should be something like :
[question_id] [exam_id] [question_text] [Marks]
10001 1001 Question1 1
10002 1001 Question2 2
10004 1001 Question4 1
10005 1001 Question5 1
10006 1001 Question6 4
10009 1001 Question9 1
答案 0 :(得分:0)
出了什么问题:
select qb.question_id, es.exam_id, qb.question_text, sum(qb.marks) Marks
from question_bank qb
inner join Chapter c on c.chapter_name = qb.chapter_name
inner join Module m on m.module_id = c.module_id
inner join exam_schedule es on es.module_id = m.module_id
group by qb.question_id, es.exam_id, qb.question_text
或者,如果exam_schedule中的[question]
映射到question_id
:
select qb.question_id, exam_id, question_text, total_marks Marks
from exam_schedule es
inner join question_bank qb on qb.question_id = exam_schedule.question