sql-server - 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”是缺少的。
解决方案
查询中缺少的是:
and b.barcode = a.barcode
将此添加到不存在的查询中就可以了。
推荐阅读
- amazon-web-services - 即使在操作失败后,如何强制 AWS CodePipeline 进入下一阶段
- javascript - 如何防止 keypress eventListner 将我的状态变量设置为 true 然后为 false?
- python - 试图从我从主调用的外部函数登录到数据库
- android - 错误:找不到正确的提供者
在此 EquipmentItemWidget$ Widget 上方 - c - 通过 fwrite stdout 的 Atmel 二进制数据防止在 0x0a 之前添加 0x0d
- json - 在 Flutter 中将新数据添加到以前的 Stream
- python - 以表格和图表作为子图的高级图形布局
- html - 用于表格的 Google App 脚本 - 从编辑器运行时 forEach 有效,但从时间触发器运行时没有数据
- optimization - 非线性模型的参数估计
- discord.py - Discord bot 一次在 dm 中发送许多问题,无需等待用户响应