mysql - Count statement in phpmyadmin -
i have 3 tables(user,questions ,answers) in question table have id_question , question, in answer table have id_question, user_id , answer. want run queury gives me number of answer's per question. want column has questions answerd(not id_question) , 3 other columns(yes,no,maybe) have number of times that answer given question. question column can't have repeated questions( though users can answer same questions , give diferent answers, want number of yes's,no's , maybe's each question).i'm created yes column ,havig trouble in creating other 2
heres did far:
select questions.question,count(answers.answer) yes answers inner join questions on questions.id_question=answers.id_question answer='yes' group question order questions.id_question asc
select questions.question, sum(if(answer='yes', 1, 0)) yes, sum(if(answer='no', 1, 0)) no, sum(if(answer='maybe', 1, 0)) maybe answers inner join questions on questions.id_question=answers.id_question group question order questions.id_question asc
Comments
Post a Comment