为什么“除外”在过滤 ID/行时有效,而“不在”中不起作用?当我运行这段代码时,我想要过滤掉的 patient_id 仍然在结果中。
Select pm.patient_id
from PatientMedication pm
Where (pm.medicine_id = 11 or pm.medicine_id = 29)
and pm.patient_id not in
Select distinct patient_id from PatientMedication pm
Where (pm.medicine_id = 11 or pm.medicine_id = 29)
and pm.start_date < '2009-03-17'
但是当我运行它时,预期的人会按照我的意愿被“过滤”掉。
Select pm.patient_id
from PatientMedication pm
Where pm.medicine_id = 11 or pm.medicine_id = 29
except
Select distinct patient_id from PatientMedication pm
Where (pm.medicine_id = 11 or pm.medicine_id = 29)
and pm.start_date < '2009-03-17'
谢谢。