日期:2014-05-18 浏览次数:20595 次
create table tb1 (author varchar(10),issueid int,content nvarchar(100),dt datetime) create table tb2 (author varchar(10),issueid int,content nvarchar(100),dt datetime) insert into tb1 values('A',1,'ABC','2012-05-26') insert into tb1 values('B',2,'ABC','2012-05-26') insert into tb1 values('C',3,'ABC','2012-05-26') insert into tb1 values('B',2,'ABC','2012-05-27') insert into tb1 values('A',1,'ABC','2012-05-27') insert into tb1 values('b',2,'ABCe','2012-05-28') insert into tb1 values('A',1,'ABCa','2012-05-28' ) insert into tb2 values('A',1,'ABC','2012-05-26') insert into tb2 values('B',2,'ABC','2012-05-26') insert into tb2 values('C',3,'ABC','2012-05-26') insert into tb2 values('b',2,'ABCdef','2012-05-27') insert into tb2 values('A',1,'ABCws','2012-05-27') insert into tb2 values('b',2,'ABC','2012-05-28') insert into tb2 values('A',1,'ABC','2012-05-28') select t1.author 姓名,t1.dt ,t1.content 昨天,t2.content 前天 from tb1 t1,tb2 t2 where t1.dt =(select MAX(dt) as date from tb1 ) and t1.issueid=t2.issueid and datediff(day,t1.dt,t2.dt) =-1 drop table tb1 drop table tb2