1

我有一个这样的查询:

SELECT t.TBarcode,t.PlateNo 
from dbo.Transaction_tbl t
WHERE Status=0 

输出:

TBarcode             PlateNo
-------------------- --------------------
6191112123456        123456
6191112123457        123458
6191112123459       123459

我还有一张EmailSendLog_tbl这样的表:

TBarcode             datetime
-------------------- --------------------
6191112123456        2013-07-19 11:12:25.000
6191112123464        2013-07-19 11:12:25.000

我想获取所有内容TBarcodePlateNoTBarcode 不包含在 中EmailSendLog_tbl,所以我尝试查询如下内容:

SELECT t.TBarcode, t.PlateNo 
from dbo.Transaction_tbl t 
WHERE Status = 0 and NOT in (SELECT TBarcode FROM dbo.EmailSendLog_tbl) 

但这显示错误:

关键字“in”附近的语法不正确

4

2 回答 2

2

将最后一行更改为:

WHERE Status=0 and t.TBarcode NOT IN(SELECT TBarcode FROM dbo.EmailSendLog_tbl) 
于 2013-08-18T08:28:28.490 回答
0

你需要放在t.TBarcode前面not in

SELECT t.TBarcode,t.PlateNo 
from dbo.Transaction_tbl t 
WHERE Status=0 and t.TBarcode NOT in (SELECT TBarcode FROM dbo.EmailSendLog_tbl) 

IN 语法

于 2013-08-18T08:29:17.460 回答