首页 > 解决方案 > SQL:从选择中排除某些条件

问题描述

尝试从查询中排除符合条件的一组值,但查询不返回任何内容。

select *
from rpt_StockInventorySummary a
where a.[DepartmentId] ='P'
and not exists (
select *
from rpt_StockInventorySummary b
where b.Manufacturer = 'warrington'
and b.LowestGroupDescription = 'Boots, Leather, 14 Inch, Pro'
and b.Instock = 0
and b.barcode = a.barcode
)
order by a.SortOrder

编辑

我认为在 NOT EXISTS 的查询末尾添加“and b.barcode = a.barcode”是缺少的。

标签: sql-serversql-server-2016

解决方案


查询中缺少的是:

and b.barcode = a.barcode

将此添加到不存在的查询中就可以了。


推荐阅读