mardi 20 décembre 2016

how can i combine rand() with sequence

this is my Database structure Database From the above image i have two types(type_id=0 & type_id=1) of questions.

EXAMPLE

1.Q.who is the president of America.?(type_id=0)

2.passage:A,B,C are 3 students Aname is "Arun" B name is "Mike" C name is "Jhon"(type_id=1). Q.who is C from the above passage

3.passage:A,B,C are 3 students Aname is "Arun" B name is "Mike" C name is "Jhon"(type_id=1). Q.who is A from the above passage

4.Q.Who is CEO of Facebook.?(type_id=0)

Form the Above 4 question we will pick random if Question 1 comes in that rand() no problem when the question 2 comes in the rand() the next question should be sequential. it means next question should be all same passage question after that passage questions completed it should switch back to rand() functionality.

And i have limit of 40 questions for test and in the table i have 50 passage questions and 70 Normal questions.

How can i write a query to call same passage questions all at one place in in between type_id=0 questions.

here is what i have tried:

SELECT *      
FROM tbl_testquestion 
ORDER BY 
    CASE 
        WHEN type_id=0 THEN RAND() 
        WHEN type_id=1 THEN qu_id 
    END ASC 

But by using this all the passage questions are coming last.

Please do suggest Edit




Aucun commentaire:

Enregistrer un commentaire