我的分组出现错误...请帮助。我的 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)