0

如果计数为 0,我如何返回一个 0 和作为可能的AnswerText 的响应?现在它不会返回任何东西。

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
4

1 回答 1

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
于 2013-07-03T16:57:17.220 回答