0

首先,我为特定模块安排了考试。模块包含超过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 
4

1 回答 1

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

或者,如果[question]在 Exam_schedule 中映射到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
于 2012-09-04T17:31:34.697 回答