22,209
社区成员
发帖
与我相关
我的任务
分享
--> 测试数据:@tb1
declare @tb1 table([id] int,[date] datetime)
insert @tb1
select 1,'2009-09-14 10:23:49.567' union all
select 1,'2009-09-03 12:00:35.346' union all
select 1,'2009-09-03 12:00:35.345' union all
select 1,'2009-09-03 12:00:35.343' union all
select 1,'2009-09-03 12:00:26.310' union all
select 1,'2009-09-03 11:58:29.310'
--> 测试数据:@tb2
declare @tb2 table([id] int,[date] datetime)
insert @tb2
select 1,'2009-09-14 10:23:49.567' union all
select 1,'2009-09-03 12:00:35.343' union all
select 1,'2009-09-03 11:58:29.310'
select * from
(
select dif=(select min(date) from @tb1 where date>t.date) from @tb2 t
) m where dif is not null
/*
dif
-----------------------
2009-09-03 12:00:35.347
2009-09-03 12:00:26.310
(2 行受影响)
*/
SELECT a,b,c=(SELECT MIN(b) FROM 表1 WHERE b>b.b) FROM 表2 b
select * from 表1
where date > (select max(date) from 表2)