我正在尝试提取患者列表,并且需要排除所有重复的 SubscriberNumber 值。我可以在没有 Where (Primary_Insurance.SubscriberNumber = 的情况下使用 Select Distinct 子句,它工作正常。当我将 (Primary_Insurance.SubscriberNumber = 添加到我的查询中时,它会忽略我的日期范围并提取与 SubscriberNumber 关联的所有约会
SELECT Primary_Insurance.SubscriberNumber, Encounter.DTTM, Patient_Iorg.OrganizationMrn AS MRN, Patient_Contact.HomePhoneArea, Patient_Contact.HomePhoneExchange, Patient_Contact.HomePhoneLast4,
Patient_Contact.LastName, Patient_Contact.FirstName, Patient_Contact.AddressLine1, Patient_Contact.AddressLine2, Patient_Contact.City, Patient_Contact.State, Patient_Contact.Zip,
Appointment.AppointmentStatusDE
FROM Appointment INNER JOIN
Encounter ON Appointment.PatientID = Encounter.PatientID INNER JOIN
Patient_Iorg INNER JOIN
Patient_Contact ON Patient_Iorg.PersonID = Patient_Contact.PatientID INNER JOIN
Primary_Insurance ON Patient_Iorg.PersonID = Primary_Insurance.patientid ON Encounter.PatientID = Primary_Insurance.patientid
WHERE (Encounter.DTTM > CONVERT(DATETIME, '2018-06-15 00:00:00', 102)) AND (Encounter.DTTM >= CONVERT(DATETIME, '2018-12-31 00:00:00', 102)) AND (Appointment.AppointmentStatusDE = 4) AND
(Primary_Insurance.SubscriberNumber = '19803782') OR
(Primary_Insurance.SubscriberNumber = '19835428') OR
(Primary_Insurance.SubscriberNumber = '19914818') OR
(Primary_Insurance.SubscriberNumber = '19993082') OR
(Primary_Insurance.SubscriberNumber = '19993082') OR
(Primary_Insurance.SubscriberNumber = '19993082')
group BY Primary_Insurance.SubscriberNumber, Encounter.DTTM, Patient_Iorg.OrganizationMrn, Patient_Contact.HomePhoneArea, Patient_Contact.HomePhoneExchange, Patient_Contact.HomePhoneLast4,
Patient_Contact.LastName, Patient_Contact.FirstName, Patient_Contact.AddressLine1, Patient_Contact.AddressLine2, Patient_Contact.City, Patient_Contact.State, Patient_Contact.Zip,
Appointment.AppointmentStatusDE;
需要弄清楚如何将 Distinct 与多个 Where 子句和内连接一起使用