问题:ID在table1中可用,但在table2中不可用,检查它的日期。需要在SQL中查询
例子:表1:
<表类>
日期
id
tbody><<tr>1-1-2020 1234 1-1-2020 5678 1-1-2020 6789 2-1-2020 567 表类>
如Charlieface所示,您似乎想要一个not exists
。下面返回您想要的结果。
declare @Table1 table ([date] date, id int);
insert into @Table1 ([date], id)
values
('2020-01-01',1234),
('2020-01-01',5678),
('2020-01-01',6789),
('2020-01-02',567);
declare @Table2 table ([date] date, id varchar(8));
insert into @Table2 ([date], id)
values
('2020-01-01','b43v1234'),
('2020-01-01','5678vgb'),
('2020-01-02','b43v1234');
select t1.id, t1.[date]
from @Table1 t1
where not exists (
select 1
from @Table2 t2
where t1.[date] = t2.[date]
and t2.id like concat('%',t1.id,'%')
);
<表类>id 日期 tbody><<tr>6789 2020-01-01 567 2020-01-02 表类>