22,210
社区成员
发帖
与我相关
我的任务
分享
select *
from
(select top 1 * from Purgdtary where ESOrdersId =58 and PurgErrorTime is not null
and purgState>0 order by abs(datediff(d,PurgErrorTime,getdate())) desc
) ta,
(select top 1 * from Purgdtary where ESOrdersId =58 and PurgEndTime is not null
and purgState>0 order by abs(datediff(d,PurgEndTime,getdate())) asc
) tb
select * from (select top 1 * from Purgdtary where ESOrdersId =58 and PurgErrorTime is not null and purgState>0 order by abs(datediff(d,PurgErrorTime,getdate())) desc )t
union all
select * from (select top 1 * from Purgdtary where ESOrdersId =58 and PurgEndTime is not null and purgState>0 order by abs(datediff(d,PurgEndTime,getdate())) asc)t
with cte1 as
(select top 1 * from Purgdtary where ESOrdersId =58 and PurgErrorTime is not null
and purgState>0 order by abs(datediff(d,PurgErrorTime,getdate())) desc)
,cte2 as(select top 1 * from Purgdtary where ESOrdersId =58 and PurgEndTime is not null
and purgState>0 order by abs(datediff(d,PurgEndTime,getdate())) asc)
select * from cte1 union all select * from cte2