グループ化でエラーが発生しています...助けてください。私のSQLコードは以下です。医師名の 1 列、メディケア患者数 2 列、非メディケア患者数 3 列を取得しようとしています。
SELECT DoctorListName,
(CASE WHEN InsuranceCarrierName IN ('Humana Medicare','Medicare','Humana Gold Plus Medicare')
THEN count(uvPatientInsurance.InsuranceCarrierName) END) as CountMedicare,
(CASE WHEN InsuranceCarrierName NOT IN ('Humana Medicare','Medicare','Humana Gold Plus Medicare')
THEN count(uvPatientInsurance.InsuranceCarrierName) END) as CountNOTMedicare
FROM (STPN.dbo.vSelectPatient vSelectPatient
INNER JOIN STPN.dbo.uvPatientInsurance uvPatientInsurance ON vSelectPatient.PatientId=uvPatientInsurance.PatientId)
INNER JOIN STPN.dbo.uvVisit uvVisit ON vSelectPatient.PatientId=uvVisit.PatientId
WHERE vSelectPatient.PatientStatusMId=-900
AND (uvVisit.Entered>={ts '2011-01-01 00:00:00'}
AND uvVisit.Entered<{ts '2012-09-30 00:00:01'})
GROUP BY DoctorListName,
(CASE WHEN InsuranceCarrierName IN ('Humana Medicare','Medicare','Humana Gold Plus Medicare')
THEN count(uvPatientInsurance.InsuranceCarrierName) END),
(CASE WHEN InsuranceCarrierName NOT IN ('Humana Medicare','Medicare','Humana Gold Plus Medicare')
THEN count(uvPatientInsurance.InsuranceCarrierName) END)