我如何在这里按问题解决分组问题。
SELECT
Tcg.ProviderID,
ISNULL(DATEDIFF(DAY , AEenc.StartDateTime , AEenc.EndDateTime),0) + ISNULL(DATEDIFF(DAY , IPenc.AdmissionDate , IPenc.ENDDate),0) as 'IPBedDays'
FROM #TargetClientGroup Tcg
INNER JOIN AEncounterDetail as AEenc
ON AEenc.ProviderID = Tcg.ProviderID
INNER JOIN [PEncounterDetail] as IPenc
ON IPenc.ProviderID = Tcg.ProviderID
--WHERE AEenc.StartDateTime >= @ReportDate
GROUP BY Tcg.ProviderID
我收到一个错误,因为它不包含在聚合函数或 GROUP BY 子句中。