日期:2014-05-17 浏览次数:20529 次
--create table t_temp
--(
-- TempId int identity(1,1) primary key,
-- TempName nvarchar(20),
-- AddTime datetime
--)
--insert into t_temp (TempName,AddTime) values('张三','2014-01-01 11:05:00')
--insert into t_temp (TempName,AddTime) values('李四','2014-01-01 11:30:00')
--insert into t_temp (TempName,AddTime) values('王五','2014-01-01 12:00:00')
--insert into t_temp (TempName,AddTime) values('张三','2014-01-02 21:00:00')
--insert into t_temp (TempName,AddTime) values('李四','2014-01-02 19:00:00')
--insert into t_temp (TempName,AddTime) values('王五','2014-01-02 23:00:00')
select a.tempid,a.tempname,CASE WHEN CONVERT(VARCHAR(10),b.addtime,120)=CONVERT(VARCHAR(10),a.addtime,120) THEN CONVERT(VARCHAR(30),CONVERT(VARCHAR(10),b.addtime,108)) ELSE CONVERT(VARCHAR(30),a.addtime,121) END addtime
From t_temp a LEFT JOIN t_temp b ON a.TempId=b.TempId+1
order by a.tempid,a.AddTime
/*
tempid tempname &