dimanche 21 décembre 2014

SQL Query Help to get Quiz statistics


I'm coding a quiz web application and i need help. I've got three tables


Nicknames : |USER_ID|NICKNAME|


that stores USER_ID(autoincrement) and NICKNAME registered to my system.


Questions : |QUESTION_ID|QUESTION_TEXT|RIGHT_ANSWER|


that contains QUESTION_ID(autoincrement value),QUESTION_TEXT that is the text of the question to show to the user and RIGHT_ANSWER which is a char that can be 'A','B','C' or 'D'.


Answers : |USER_ID|QUESTION_ID|ANSWER_GIVEN|


USER_ID references Nicknames.USER_ID QUESTION_ID references Questions.QUESTION_ID ANSWER_GIVEN is the answer that user gave(and so it should be A,B,C or D as in Questions)


I need to count with a query how many correct answers each user gave for all questions in database.


(example of result)


NICKNAME|TOTAL_CORRECT_ANSWERS

Nick1 | 0

Nick2 | 5


and so on...


Notice that i would like to get 0 in the SQL result if the user did not answer correctly at all. Thank you very much!





Aucun commentaire:

Enregistrer un commentaire