0

So I've been stumped on this for a while and can't seem to find an answer.

this is my database diagram

enter image description here

I'm supposed to find give the command to show the average response broken down by each question. I'm sure there is some really simple solution to this but I must be over thinking it or completely missing something obvious. There are 6 questions total in the questions table.

tshepang
  • 12,111
  • 21
  • 91
  • 136

1 Answers1

1

Try like this:

SELECT q.id, AVG(s.survey_response)
FROM survey_questions q
INNER JOIN survey_responses s ON q.id = s.survey_question_id
GROUP BY q.id
Filipe Silva
  • 21,189
  • 5
  • 53
  • 68
  • omg I feel so stupid... so after all I tried all I needed was a group by statement... obviously my understanding of what group by did was confused. Thanks again so much! – gaurdianAQ Oct 23 '13 at 15:53
  • as soon as I figure out how sure. Also is there any particular advantage to using an inner join over just a regular join for this? – gaurdianAQ Oct 23 '13 at 15:59
  • [Here](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235) is how accepting an answer works. About the inner join, it is a regular join that takes only the rows that match on the two sides of the join.:). See this [answer](http://stackoverflow.com/a/16598900/1385896) for more information on JOINS – Filipe Silva Oct 23 '13 at 16:01
  • normally I'm able to just google my question or ask someone else... this might become my go to site for programming related stuff... I might also have to start answering questions. Alright thanks again and have a good day! – gaurdianAQ Oct 23 '13 at 16:03