dimanche 3 juillet 2016

Getting count of same fileds in Table SQL

I have 3 tables

1)question  
2)question_option
3)user_answer

Table 1 contains list of multiple choice questions. Table 2 contains multiple choices for the question.

Consider an example, I have the question "Which game do you like most?"

It is stored in table 1 with id 1. For this question there are 3 choices in table 2; as "cricket", "football", "tennis" with ids 1,2 & 3.

When a user answer this question the question id, and option id are stored to the third table as if he select football, entry in table 3 is question id and option id.

If another user select same option new entry is stored in table 3.

My need is that I want to get the count of each options in table 3.

Consider 10 users select cricket, 15 users select football, no user select tennis, so I need count as 10,15,0 with its corresponding option id

Aucun commentaire:

Enregistrer un commentaire