I have the following database design:
Answers Table: AnswerID, Answer
QuestionAnswers Table: ID, QuestionID, AnswerID
CompleteSurvey Table: ID, QuestionAnswersID, RespondantID
Questions Table: QuestionID, Question
Employee Table: EmployeeID, Name
In one of the questions, I have the following answers:
ER Estimate
Company Esitmate
Both ER & Company Estimates
None
The answer of this question will affect two questions. What I want now, is to exclude the employees who selected (None) and then exclude them from number of participants in the other two questions. So how to do that?
Let us assume that we have three questions which are A, B and C. So how am I going to be able to exclude the people who selected (None) as an answer for question A from the number of employees who participated in Question B and C.
I wrote the query that shows me the number of participants in each possible answer for each question and it works well, but how I can improve it to get what I want above:
SELECT COUNT(DISTINCT dbo.CompleteSurvey.RespondantID) AS [Total Number of Participants], dbo.Answers.Answer, dbo.Questions.Question
FROM dbo.Questions INNER JOIN
dbo.QuestionsAnswers ON dbo.Questions.QuestionID = dbo.QuestionsAnswers.QuestionID INNER JOIN
dbo.Answers ON dbo.QuestionsAnswers.AnswerID = dbo.Answers.AnswerID LEFT OUTER JOIN
dbo.CompleteSurvey ON dbo.QuestionsAnswers.ID = dbo.CompleteSurvey.QuestionsAnswersID
GROUP BY dbo.Answers.Answer, dbo.Questions.Question
UPDATE 2:
148 Both ER & Company Estimates
102 Company Estimate
22 ER Estimate
130 None
The number of participants in each possible answer for Question A. Now for Question B, let us assume we have the following answers and number of participants:
22 Answer A
180 Answer B
180 Answer C
20 Answer D
When I applied you query to exclude the people with (None) answer in Question A from the following questions, I got negatives numbers for the all answers in Question B. How it can be like this?
Perhaps this might work:
You will have to know beforehand the
IDfor the question-answer combination you want to exclude, and insert it where it says<id>in the query.