Hi,
I have a table which stores the answer of a survey question of a user (multiple choice).
Now I am using this statement to read the number of each answer that was given for a question for ALL users:
SELECT TOP 100 PERCENT dbo.surveyresults_answers.ans_quid AS QuestionId, dbo.surveyresults_answers.ans_squid AS SubQuestionId,
dbo.surveyresults_answers.ans_optid AS OptionID, COUNT(dbo.surveyresults_answers.ans_answerid) AS NumberOfResponses,
dbo.surveyresults_answers.ans_responsecharvalue AS Answer, dbo.survey_columns.col_name AS Category
FROM dbo.surveyresults_answers INNER JOIN
dbo.survey_columns ON dbo.surveyresults_answers.col_columnid = dbo.survey_columns.col_columnid
GROUP BY dbo.surveyresults_answers.ans_quid, dbo.surveyresults_answers.ans_squid, dbo.surveyresults_answers.ans_responsecharvalue,
dbo.survey_columns.col_name, dbo.surveyresults_answers.ans_optid
ORDER BY dbo.surveyresults_answers.ans_quid, dbo.surveyresults_answers.ans_squid
This works. But now I have to count the numbers of each answer of ONLY THE USERS who gave a CERTAIN answer in the survey. I think I need to add a subquery somewhere in the count statement....
I have a table which stores the answer of a survey question of a user (multiple choice).
Now I am using this statement to read the number of each answer that was given for a question for ALL users:
SELECT TOP 100 PERCENT dbo.surveyresults_answers.ans_quid AS QuestionId, dbo.surveyresults_answers.ans_squid AS SubQuestionId,
dbo.surveyresults_answers.ans_optid AS OptionID, COUNT(dbo.surveyresults_answers.ans_answerid) AS NumberOfResponses,
dbo.surveyresults_answers.ans_responsecharvalue AS Answer, dbo.survey_columns.col_name AS Category
FROM dbo.surveyresults_answers INNER JOIN
dbo.survey_columns ON dbo.surveyresults_answers.col_columnid = dbo.survey_columns.col_columnid
GROUP BY dbo.surveyresults_answers.ans_quid, dbo.surveyresults_answers.ans_squid, dbo.surveyresults_answers.ans_responsecharvalue,
dbo.survey_columns.col_name, dbo.surveyresults_answers.ans_optid
ORDER BY dbo.surveyresults_answers.ans_quid, dbo.surveyresults_answers.ans_squid
This works. But now I have to count the numbers of each answer of ONLY THE USERS who gave a CERTAIN answer in the survey. I think I need to add a subquery somewhere in the count statement....