【发布时间】:2014-12-06 08:59:02
【问题描述】:
如何从日期之间不存在数据的sql表中获取数据
我正在使用三个表
- 客户大师
- 每日调度
- EmptyCylinderRecd
我想查找不在Dailydispatch 和EmptyCylinderRecd 表中的客户。我已尝试过此查询,但未显示预期结果:
select *
from CustomerMaster
where
not EXISTS (select *
from DailyDispatch
where OrderDate between '1/22/2014' and '08/10/2014') or
not exists (select *
from EmptyCylinderRecd
where Date between '1/22/2014' and '08/10/2014')
【问题讨论】:
-
能展示一下表格结构吗?
-
表之间的关系是什么???
-
三个表之间的关系是Name是公共字段
-
@Sarvan - 您希望客户出现在表 1 中,而不是 2,3 中?
-
@BoratSagdiyev 完全正确,我希望客户在表 1 中,而谁不在表 2,3 中。
标签: sql sql-server exists not-exists