# 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()
``````

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?
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Technical 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()
``````
1

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Business Systems Analyst , ex-Senior Application EngineerCommented:
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.
1
Author Commented:
Thanks Nakul it works
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.