我正在尝试在下面的查询中按县分组并按县排序,但它不起作用。我怎样才能让它按县分组和排序?
select COUNT(sr.Response) as 'Number Of Responses',
County =
(select qpa.PossibleAnswerText from CaresPlusParticipantSurvey.QuestionPossibleAnswer as qpa
join CaresPlusParticipantSurvey.SurveyResponse as sr1 on qpa.Id = sr1.QuestionPossibleAnswerId
where (sr1.QuestionId = 1 and sr.SurveyId = sr1.SurveyId))
FROM CaresPlusParticipantSurvey.SurveyResponse as sr
where (sr.Response is not null and CAST(sr.Response as int) < 6) and (sr.QuestionId = 8)
Group BY sr.Response, sr.SurveyId
Order by County
下面的结果是当前查询的当前结果。我希望它按县分组,所以 4 Alameda 1 Colusa 8 Contra Costa
1 Alameda
1 Alameda
1 Alameda
1 Alameda
1 Colusa
1 Contra Costa
1 Contra Costa
1 Contra Costa
1 Contra Costa
1 Contra Costa
1 Contra Costa
1 Contra Costa
1 Contra Costa