0

为什么“除外”在过滤 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' 

谢谢。

4

1 回答 1

0

Would this be what you are trying to accomplish

Select pm.patient_id 
from PatientMedication pm 
Where (pm.medicine_id = 11 or pm.medicine_id = 29) 
AND pm.start_date >= '2009-03-17'
于 2013-06-27T18:54:22.503 回答