日期:2014-05-17 浏览次数:20642 次
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
------解决方案--------------------
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
------解决方案--------------------
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