小编典典

NOT IN查询不起作用,SQL Server 2008

sql

查询的第一部分在not in运行之前为我提供了100条记录的列表。第二个查询运行,并提供75条记录的列表。我尝试使用的查询not in是获取一个结果集中的记录,而不是另一个。我得到的错误是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


阅读 208

收藏
2021-04-15

共1个答案

小编典典

您需要指定第二个查询中没有的字段

and Patient.patientid not in
2021-04-15