【发布时间】:2020-02-19 21:54:42
【问题描述】:
我有一个不存在的 SQL 查询,用于从最终结果中排除一组特定值。
select distinct
from [rpt_StockInventorySummary] a
where a.[DepartmentId] ='P'
and not exists (
select *
from rpt_StockInventorySummary b
where b.DepartmentId = 'p'
and b.Manufacturer = 'warrington'
and b.LowestGroup = 57 and b.Instock = 0
and b.Barcode = a.Barcode
)
order by a.SortOrder
查询工作正常,但现在我需要修改 SQL,以便从最终结果中排除另一组值。所以我试着像这样修改NOT EXISTS里面的SQL。
select *
from rpt_StockInventorySummary b
where b.DepartmentId = 'p'
and b.Manufacturer = 'warrington'
and (b.LowestGroup = 57 and b.Instock = 0)
or b.LowestGroup = 60
and b.Barcode = a.Barcode
查询本身运行并返回值就好了。但是当我运行整个查询时,我没有得到任何结果。我该如何解决这个问题?
【问题讨论】:
标签: sql-server-2016 not-exists