Setting up question paper matching with count of questions and time

Hi all I have a table where I am storing the number of questions to be displayed and time to be spent on that.

SectionId   QuizId     SubjectId   QuestionCnt    Totaltime
    1                  1                 1                   5                    30

But when I am selecting question I am following an approach to select questions randomly that falls under time to answer between 1 and 30

Select QuestionDesc, Maxtime from Question where Maxtime between 1 and 30 ORDER BY NEWID()

Open in new window

Which is giving me random questions and I am sorting the question that was answered in to a separate table and calculating the left over time before loading another question.

Let us say 1 question loaded which if of 5 minutes then he has 25 minutes left for remaining questions. But the problem here is some times I am getting 5 questions and some time I am getting 3 questions which falls under the time limit like (3*10). But I need to get 5 questions to be answered is it possible?
Chaitanya VAsked:
Who is Participating?
Nakul VachhrajaniTechnical Architect, Capgemini IndiaCommented:
I would recommend changing the way in which questions are selected. Rather than filtering on the total time, can't you get all questions whose time is less than or equal to your average time?

For example, in your case, the candidate has (Totaltime/QuestionCnt) = (30/5) = 6 minutes for each question.

Hence, can't you fetch those questions whose maxtime is 6 minutes or less?

Select QuestionDesc, Maxtime from Question where Maxtime between 1 and (Totaltime/QuestionCnt) ORDER BY NEWID()

Open in new window

Ryan ChongCommented:
I would suggest in your table: Question, add a new field as "TotalTimeOccupied", so that in the query later, you can group 5 random questions that in total occupied the time limit you specified, in this case 30 mins.

hope that make sense.
Chaitanya VAuthor Commented:
Thanks Nakul it works
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.