我的 SQL 有点生疏,只是好奇是否有更好的方法来执行此 WHERE 子句?假设有一种方法,我确信有。它的运行速度非常快,但我只是不喜欢它,想知道它是否可以改进。
SELECT DISTINCT p.firstname ,
p.middlename ,
p.lastname ,
p.gender ,
p.dob ,
p.id AS patientid ,
pr.id AS practiceid ,
pr.[name] AS practicename,
pr.parentaco ,
pp.encounterdate
FROM ((aco.patients_practices patients_practices
LEFT OUTER JOIN aco.patients p
ON (
patients_practices.patientid = p.id
)
)
LEFT OUTER JOIN aco.practices pr
ON (
patients_practices.practiceid = pr.id
)
)
INNER JOIN aco.patientpreferences pp
ON (
pp.patientid = p.id
)
WHERE (
pr.parentaco =
(SELECT parentaco
FROM aco.practices
WHERE master_companyid = 763
)
OR pr.id =
(SELECT parentaco
FROM aco.practices
WHERE master_companyid = 763
)
)
AND pp.encounterdate IS NOT NULL