我有一个查询来询问没有后续事件的咨询。
SELECT p.person_nbr
, p.last_name + ',' + p.first_name as [Full Name]
, pm.last_name as Provider
, pe.enc_id
, e.event
, pe.enc_timestamp
FROM person p
JOIN patient_encounter pe
ON p.person_id = pe.person_id
JOIN appointments a
on a.enc_id = pe.enc_id
JOIN events e
ON a.event_id = e.event_id
JOIN provider_mstr pm
ON pe.rendering_provider_id = pm.provider_id
--where pe.enc_timestamp >= '20180713' and pe.enc_timestamp <= '20181030'
GROUP BY p.person_nbr, p.last_name + ',' + p.first_name , pm.last_name ,
pe.enc_id
, e.event , pe.enc_timestamp
HAVING SUM(CASE WHEN e.event like 'Consult' and pe.enc_timestamp >=
'20180713' AND pe.enc_timestamp <= '20181030' THEN 1 ELSE 0 END) > 0 AND
SUM(CASE WHEN e.event like 'Follow Up' THEN 1 ELSE 0 END) >= 1
order by p.person_nbr
;
我认为,如果某人在hading子句中指定的日期内进行了咨询,然后另外声明说他们没有后续行动,那将是可行的,但我没有结果。香港专业教育学院试图移动日期以及where子句。我认为我没有得到结果,因为它的想法是询问单个事件是否既是咨询又是后续活动,但是我希望它返回将来没有后续跟进的单个咨询。