我正在尝试捕获以下内容:
上次就诊日期(Eventdate)的就诊地点为 Lab 的患者列表。我需要提取过去 3 个月的数据。下面的查询运行良好,但是当我进行一些 QA 时,我发现对于一些出现 LAB 的患者来说,这不是他们的最后一次访问。我的查询有什么问题?
谢谢你的帮助。
SELECT
SSKeyField=Event_AntiCoag.SS_Event_AntiCoag_ID,
SSParentField=A.SS_Patient_ID,
A.Last_Name,
A.First_Name,
A.Patient_ID,
A.MaxOfEventDate,
A.VisitLoc,
A.Active
FROM
(SELECT Demographics.Last_Name, Demographics.First_Name
, Demographics.SS_Patient_ID, Demographics.Patient_ID
, Max(Event_AntiCoag.EventDate) AS MaxOfEventDate
, AntiCoag_Extension.VisitLoc
, Demographics_Extension.Active
FROM ((Event_AntiCoag INNER JOIN Demographics ON Event_AntiCoag.SS_Patient_ID = Demographics.SS_Patient_ID) INNER JOIN AntiCoag_Extension ON Event_AntiCoag.SS_Event_AntiCoag_ID = AntiCoag_Extension.SS_Event_AntiCoag_ID) INNER JOIN Demographics_Extension ON Event_AntiCoag.SS_Patient_ID = Demographics_Extension.SS_Patient_ID
GROUP BY Demographics.Last_Name, Demographics.First_Name, Demographics.SS_Patient_ID
, Demographics.Patient_ID, AntiCoag_Extension.VisitLoc, Demographics_Extension.Active
)A
INNER JOIN (Event_AntiCoag INNER JOIN AntiCoag_Extension
ON Event_AntiCoag.SS_Event_AntiCoag_ID = AntiCoag_Extension.SS_Event_AntiCoag_ID)
ON (A.MaxOfEventDate = Event_AntiCoag.EventDate)
AND (A.SS_Patient_ID = Event_AntiCoag.SS_Patient_ID)
WHERE A.Active=1
AND ((A.VisitLoc='Lab') AND (A.MaxOfEventDate >= '4/1/2013'))
ORDER BY A.Last_Name, A.First_Name