首页 > 数据库技术 > 详细

SQL server 时间处理自连接

时间:2015-12-11 18:26:15      阅读:254      评论:0      收藏:0      [点我收藏+]
 --延时的订单
select
t1.OrderId order1, t1.VerifyStatusId id1,t1.VerifyDate ‘时间1‘,
t2.OrderId order2, t2.VerifyStatusId id2,t2.VerifyDate ‘时间2‘,
t1.VerifyStatus ‘状态1‘,
t2.VerifyStatus ‘状态2‘,
datediff(n, t2.VerifyDate,t1.VerifyDate) ‘延时‘
from T_VerifySituation t1, T_VerifySituation t2
where 1 =1 
and (t1.VerifyStatusId>t2.VerifyStatusId)
and (t1.OrderId=t2.OrderId)
and (datediff(d, t2.VerifyDate,t1.VerifyDate)>1)--延时时长大于一天
and 
(
(t2.VerifyStatus=3024 and t1.VerifyStatus=3013)or--初审用时
(t2.VerifyStatus=3013 and t1.VerifyStatus=3018)or--终审用时
(t2.VerifyStatus=3018 and t1.VerifyStatus=1008)or--综评用时
(t2.VerifyStatus=1019 and t1.VerifyStatus=1010)  --复议用时
)

SQL server 时间处理自连接

原文:http://www.cnblogs.com/dullbaby/p/5039613.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!