求教sql语句两个日期、时间字段相减得到天数小时分秒的问题

selectrequestid,userid,workflowid,receivedate,receivetime,operatedate,operatetimefrom... select requestid,userid,workflowid,receivedate,receivetime,operatedate,operatetimefrom workflow_currentoperator where workflowid=297 and requestid=110215 order by receivedate,receivetime如下图,通过上述语句查询处结果;希望得到字段:operatedate,operatetime;减去字段receivedate,receivetime;得到一个天数小时分秒的结果。 请教下语句怎么写? 展开
 我来答
传说中的鹰王
2018-08-06 · TA获得超过1053个赞
知道小有建树答主
回答量:923
采纳率:87%
帮助的人:547万
展开全部
select requestid,userid,workflowid,receivedate,receivetime,operatedate,operatetime,
cast(day as varchar)+'天'+cast((hour-day*24) as varchar)+'小时'+
cast((minute-hour*60) as varchar)+'分'+
cast((second-minute*60) as varchar)+'秒' result
from(
select requestid,userid,workflowid,receivedate,receivetime,operatedate,operatetime,
datediff(d, CONVERT(datetime,receivedate+' '+receivetime,20), 
CONVERT(datetime,operatedate+' '+operatetime,20)) day,
datediff(hh, CONVERT(datetime,receivedate+' '+receivetime,20), 
CONVERT(datetime,operatedate+' '+operatetime,20)) hour,
datediff(n, CONVERT(datetime,receivedate+' '+receivetime,20), 
CONVERT(datetime,operatedate+' '+operatetime,20)) minute,
datediff(s, CONVERT(datetime,receivedate+' '+receivetime,20), 
CONVERT(datetime,operatedate+' '+operatetime,20)) second
from workflow_currentoperator 
where workflowid=297 and requestid=110215 
) t
order by receivedate,receivetime
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式