为什么“except”可以过滤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'
感谢。
答案 0 :(得分:0)
这是你想要完成的事情
Select pm.patient_id
from PatientMedication pm
Where (pm.medicine_id = 11 or pm.medicine_id = 29)
AND pm.start_date >= '2009-03-17'