tabel1:
id projcode actionname cu_date
801190 148554 案卷批转 15:04:43
801194 148554 立案处理 15:04:51
801199 148554 任务分派 15:05:05
802250 148554 结果反馈 17:06:18
802253 148554 送操作员核查 17:06:25
802255 148554 发核查指令 17:06:41
802330 148554 发核查指令 17:19:21
802338 148554 核查不属实 17:21:28
802361 148554 任务分派 17:26:13
802584 148554 结果反馈 18:57:26
803029 148554 送操作员核查 8:49:25
803044 148554 发核查指令 8:49:49
804165 148554 发核查指令 10:14:03
804234 148554 核查属实 10:21:08
804280 148554 结案 10:24:48
我现在想罗列出任务分派,和任务分派前一步的数据求结果如下
801194 148554 立案处理 15:04:51
801199 148554 任务分派 15:05:05
802338 148554 核查不属实 17:21:28
802361 148554 任务分派 17:26:13
id projcode actionname cu_date
801190 148554 案卷批转 15:04:43
801194 148554 立案处理 15:04:51
801199 148554 任务分派 15:05:05
802250 148554 结果反馈 17:06:18
802253 148554 送操作员核查 17:06:25
802255 148554 发核查指令 17:06:41
802330 148554 发核查指令 17:19:21
802338 148554 核查不属实 17:21:28
802361 148554 任务分派 17:26:13
802584 148554 结果反馈 18:57:26
803029 148554 送操作员核查 8:49:25
803044 148554 发核查指令 8:49:49
804165 148554 发核查指令 10:14:03
804234 148554 核查属实 10:21:08
804280 148554 结案 10:24:48
我现在想罗列出任务分派,和任务分派前一步的数据求结果如下
801194 148554 立案处理 15:04:51
801199 148554 任务分派 15:05:05
802338 148554 核查不属实 17:21:28
802361 148554 任务分派 17:26:13
with cte as (select row=row_number()over(order by cu_date),* from table) select * from cte where actionname='任务分派'
union
select * from cte where row in(select row-1 from cte where actionname='任务分派' )
with cte as (select row=row_number()over(order by cu_date),* from table) select * from
(select id,projcode,actionname,cu_date from cte where actionname='任务分派'
union
select id,projcode,actionname,cu_date from cte
where row in(select row-1 from cte where actionname='任务分派' )) t
order by cu_date
with cte as (select row=row_number()over(order by cu_date),* from table) select datediff(second,t2.cu_date,t1.cu_date) from
(select * from cte where actionname='任务分派')t1
left join
(select * from cte where row in(select row-1 from cte where actionname='任务分派'))t2
on t1.row=t2.row+1
order by datediff(second,t2.cu_date,t1.cu_date) desc