Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with a query

Status
Not open for further replies.

Kai77

Programmer
Jun 7, 2004
77
NL
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....
 
Try adding a WHERE clause right above the GROUP BY.

WHERE dbo.surveyresults_answers.ans_responsecharvalue = <insert value of answer you want here>



Catadmin - MCDBA, MCSA
"If a person is Microsoft Certified, does that mean that Microsoft pays the bills for the funny white jackets that tie in the back???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top