select a.*,datediff(ss,a.deCreateDatetime_datetime,b.deCreateDatetime_datetime)/2 as 時間差的平均值,
(select top 1 deCreateDatetime_datetime from myOrder_DE d where deType_nvarcharN"IR"
and d.deCreateDatetime_datetime>a.deCreateDatetime_datetime order by d.deCreateDatetime_datetime)
as IR下一個狀態的時間
from myOrder_DE a inner join myOrder_DE b
on a.deType_nvarchar=N"IR"
and a.deid_int(select max(deid_int) from myOrder_DE where deType_nvarchar=N"IR")
and b.deid_int=(select top 1 deid_int from myOrder_DE
where deid_int
where c.deType_nvarchar=N"IR" and c.deid_int>a.deid_int order by c.deid_int) order by deid_int desc)
order by b.deCreateDatetime_datetime
select a.*,datediff(ss,a.deCreateDatetime_datetime,b.deCreateDatetime_datetime)/2 as 時間差的平均值,
(select top 1 deCreateDatetime_datetime from myOrder_DE d where deType_nvarcharN"IR"
and d.deCreateDatetime_datetime>a.deCreateDatetime_datetime order by d.deCreateDatetime_datetime)
as IR下一個狀態的時間
from myOrder_DE a inner join myOrder_DE b
on a.deType_nvarchar=N"IR"
and a.deid_int(select max(deid_int) from myOrder_DE where deType_nvarchar=N"IR")
and b.deid_int=(select top 1 deid_int from myOrder_DE
where deid_int
where c.deType_nvarchar=N"IR" and c.deid_int>a.deid_int order by c.deid_int) order by deid_int desc)
order by b.deCreateDatetime_datetime