Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Survey questions and answers.

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-04-02 : 09:13:51
Chris writes "Trying to graph the results of the answers to a list of survey questions...

The survey can be taken x amount of times.
There are 10 questions.
Each question can have 1 to 5 answers.

There are three tables...tblQuestions, tblAnswers and tblResponses (w/questionID, answerID)

I need to find...
# times each question has been answered.
# of times each answer within each question has been chosen (including 0's)...which should add up to the previous number."

Nazim
A custom title

1408 Posts

Posted - 2002-04-02 : 09:20:44
Try something on these lines


select q.questionid, count(*), sum( case r.response when 0 then 1 else null end)
from tblQuestion Q
inner join tblAnswers A
A.questionid=q.questionid
left Join tblResponse r
on r.questionid=a.questionid and r.answerid=a.answerid
group by q.questionid


--------------------------------------------------------------
Go to Top of Page
   

- Advertisement -