根据sql中的日期获取相应表中不存在的所有行

根据sql中的日期获取相应表中不存在的所有行,sql,sql-server,tsql,Sql,Sql Server,Tsql,我有两张表:表A和表B(如下图所示): 结果应如下图所示: 使用mssql查询获得结果(如表结果)的最佳方法是什么 谢谢。如果我理解正确,您想要的是不存在的日期/值对 使用交叉联接生成所有日期/值对的列表。然后过滤掉你不想要的: select b.value, d.date from tableb b cross join (select distinct date from tablea a) d where not exists (select 1 from tablea a

我有两张表:表A和表B(如下图所示):

结果应如下图所示:

使用mssql查询获得结果(如表结果)的最佳方法是什么


谢谢。

如果我理解正确,您想要的是不存在的日期/值对

使用交叉联接生成所有日期/值对的列表。然后过滤掉你不想要的:

select b.value, d.date
from tableb b cross join
     (select distinct date from tablea a) d
where not exists (select 1 from tablea a where a.date = d.date and a.value = b.value)

如果我理解正确,您需要不存在的日期/值对

使用交叉联接生成所有日期/值对的列表。然后过滤掉你不想要的:

select b.value, d.date
from tableb b cross join
     (select distinct date from tablea a) d
where not exists (select 1 from tablea a where a.date = d.date and a.value = b.value)

结果集的逻辑是什么?不要害羞。结果集的逻辑是什么?不要害羞。@MaxSzczurek。谢谢你。@MaxSzczurek。非常感谢。