借此题再问个问题<br>--测试<br>use tempdb<br>go<br><br>create table #t1(id int identity,K1 varchar(10),name varchar(10)) --员工表<br>create table #t2(id int identity,K1 varchar(10), T3 int,[date] datetime) --记录表<br>create table #t3(id int,[type] varchar(2)) --设备表<br><br>--三表关系(#t1与#t2 K1=K1 #t2与#t3 T3=id)<br><br>insert #t1 select 'A1','张三'<br>union all select 'A2','李四'<br>union all select 'A3','王麻子'<br><br>insert #t2 select 'A1','1','2006-04-05 10:21:34'<br>union all select 'A1','1','2007-09-05 09:21:34'<br>union all select 'A1','2','2008-03-01 10:21:34'<br>union all select 'A2','1','2006-04-05 10:21:34'<br>union all select 'A2','2','2007-09-05 09:21:34'<br>union all select 'A2','1','2008-03-01 10:21:34'<br>union all select 'A3','2','2006-04-05 10:21:34'<br>union all select 'A3','2','2007-09-05 09:21:34'<br>union all select 'A3','2','2008-03-01 10:21:34'<br>union all select 'A3','2','2006-04-05 10:21:34'<br><br><br>insert #t3 select 1,'进'<br>union all select 2,'出'<br><br><br>select * from #t1<br>select * from #t2<br>select * from #t3<br><br><br>/*<br><date> 输入日期<br>查询出在<date>之后没有进来的人员以及最近进来时间和上次出去时间<br><br>结果格式 id K1 name 最近进入时间 上次出去时间<br><br><br>--谁知道这个查询怎么写?<br><br><br>*/<br><br>--没有进来的人员<br><br>select a.* from #t1 a where a.K1 not in (select a.K1 from #t1 a inner join #t2 b on a.K1=b.K1 inner join <br> #t3 c on b.t3=c.id and [type]='进' and convert(varchar(10),b.[date],120)> '2008-02-01')<br><br>--完整的应该怎么写,请指定<br><br>drop table #t1,#t2<br><br><br>大家帮我看看应该如何写这个SQL语句呢?谢谢了...