我有两个表:
产品表
ProductID Name Date
1 ABC 2020-02-14
2 XYZ 2020-03-05
Productbreak_Table
BreakID Product_id Begin End
34 1 2020-01-01 2020-01-30
35 1 2020-02-01 2020-02-20
36 2 2020-01-15 2020-01-31
37 2 2020-02-15 2020-03-01
我的目标是只获得Date
不在productbreak_table 的Begin
和End
日期之间的产品
结果应该是:
ProductID Name
2 XYZ
您将使用not exists
:
select p.*
from products p
where not exists (select 1
from productbreak pb
where pb.productid = p.productid and
p.date between pb.begin and pb.end
);