34,588
社区成员
发帖
与我相关
我的任务
分享
create table #table1(test_id int,test_time datetime)
create table #table2(tb2_id int,tb2_time datetime)
insert into #table1 select 1,'2016-01-10'
insert into #table1 select 2,'2016-01-10'
insert into #table1 select 1,'2016-01-11'
insert into #table1 select 2,'2016-01-11'
insert into #table2 select 1,'2016-01-10'
insert into #table2 select 2,'2016-01-10'
--求查询输出
select * from #table1
select test_id,test_time from (select * from #table1 left join #table2 on test_id=tb2_id) as a where datediff(day,tb2_time,test_time)>3--如果你要3天不要就这样是几天就大与几天
[/quote]
谢谢了
select test_id,test_time from (select * from #table1 left join #table2 on test_id=tb2_id) as a where datediff(day,tb2_time,test_time)>3--如果你要3天不要就这样是几天就大与几天
select b.id,b.time1 from tb2 as b
where a.id=b.id and a.time1=b.time1
select a.id,a.name,a.time1 from tb1 as a
where not exists(
select b.id,b.time1 from tb2 as b
where a.id=b.id and a.time1=b.time1)
select test_id,test_time from #table1 except select tb2_id,tb2_time from #table2