NOT IN 查询不起作用,SQL Server 2008 [英] NOT IN query not working, SQL Server 2008
本文介绍了NOT IN 查询不起作用,SQL Server 2008的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
not in
之前查询的第一部分运行并给我一个 100 条记录的列表.第二个查询运行并给我一个包含 75 条记录的列表.我尝试使用 not in
编写的查询是获取一个结果集中的记录,而不是另一个结果集中的记录.我得到的错误是 not 附近的语法不正确
.
The first part of the query before not in
runs and gives me a list of 100 records. The second query runs and gives me a list of 75 records. The query I'm trying to write using not in
is to get the records that are in one result set, but not the other. The error I get is incorrect syntax near the word not
.
SELECT distinct Patient.patientid
FROM Patient INNER JOIN
patientICD ON Patient.patientid = patientICD.patientid AND Patient.admissiondate = patientICD.admissiondate AND
Patient.dischargedate = patientICD.dischargedate INNER JOIN
tblICD ON patientICD.primarycode = tblICD.ICD_ID
WHERE (tblICD.descrip LIKE N'%diabetes%') and not in
(
SELECT distinct Patient.patientid
FROM Patient INNER JOIN
patientICD ON Patient.patientid = patientICD.patientid AND Patient.admissiondate = patientICD.admissiondate AND
Patient.dischargedate = patientICD.dischargedate INNER JOIN
tblICD ON patientICD.primarycode = tblICD.ICD_ID
WHERE (tblICD.icd_id LIKE N'25000')
)
是否曾经允许使用 expression AND NOT IN (select query
) 编写查询?
Is it ever allowed to write a query with expression AND NOT IN (select query
?
推荐答案
需要指定第二个查询中没有的字段
You need to specify what field is not in the second query
and Patient.patientid not in
这篇关于NOT IN 查询不起作用,SQL Server 2008的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文