如果count为0,如何使用PossibleAnswerText作为响应返回0?现在它不会返回任何东西。
select
COUNT(sr.Id) AS 'Responses', qpa.PossibleAnswerText
from
CaresPlusParticipantSurvey.QuestionPossibleAnswer as qpa
join
CaresPlusParticipantSurvey.SurveyResponse as sr on sr.QuestionPossibleAnswerId = qpa.Id
where
sr.QuestionPossibleAnswerId = 116
GROUP BY
qpa.PossibleAnswerText
答案 0 :(得分:1)
您需要使用LEFT JOIN
,并从WHERE
子句中删除“最右侧”表格中的条件;
SELECT COUNT(sr.Id) AS 'Responses', qpa.PossibleAnswerText
FROM CaresPlusParticipantSurvey.QuestionPossibleAnswer AS qpa
LEFT JOIN CaresPlusParticipantSurvey.SurveyResponse as sr
ON sr.QuestionPossibleAnswerId = qpa.Id
WHERE qpa.Id = 116
GROUP BY qpa.PossibleAnswerText