0

我有两个表如下..

  1. tbPatientEncounter
  2. tb代金券

当我执行select query如下

Select EncounterIDP,EncounterNumber from tbPatientEncounter

在此处输入图像描述

它让我恢复了 180 行。和

从 tbVoucher 中选择 VoucherIDP,EncounterIDF

在此处输入图像描述

上面的查询返回我 165 行。

但我想执行选择查询,该查询返回我的数据,如 EncounterIDP 不在 tbVoucher 中,因为我在选择查询下面尝试过...

    Select * from tbPatientEncounter pe 
    where pe.EncounterIDP not in 
    (Select v.EncounterIDF from tbVoucher v )

它不返回任何行。在它显示的第一张图片中EncounterIDP 9 in tbPatientEncounter,但它没有插入到 tbVoucher 中,因为我尝试过 select Query like

Select * from tbVoucher where EncounterIDF = 9 

它返回我 0 行。

我的问题是what is wrong with my above Not In Query.?

4

3 回答 3

2

您是否在比较 tbVoucher 中的正确字段?

尝试使用左连接

Select EncounterIDP,EncounterNumber from tbPatientEncounter
       left join tbVoucher on EncounterIDP = EncounterIDF
where EncounterIDF is null
于 2013-08-24T09:36:01.630 回答
2

很可能,问题出NULLtbVoucher. 尝试这个:

Select *
from tbPatientEncounter pe 
where pe.EncounterIDP not in (Select v.EncounterIDF
                              from tbVoucher v
                              where v.EncounterIDF is not NULL
                             )
于 2013-08-24T11:52:29.180 回答
0

称我为怀疑论者,因为我认为您的查询没有任何问题。这真的是查询中的全部内容还是您为我们简化了它?

Select * from tbPatientEncounter pe 
where pe.EncounterIDP not in 
(Select v.EncounterIDF from tbVoucher v )
于 2013-08-24T17:45:19.707 回答