如何找到列中2行之间的时间差

时间:2014-02-18 21:18:05

标签: mysql sql

嗨当我使用此查询时,它会给我一个2列,每行都有一个请求和一个响应。如何在几秒钟内消除这两者之间的时差。

select M.MSG_DESC, M.Msg_Ts from INTLOG.ESB_MSG_L M,INTLOG.ESB_PAYLOAD_L P
where M.MSG_ID = P.MSG_ID
And M.Msg_Ts >= Timestamp'2014-02-16 00:00:00' 
And M.Msg_Ts <= Timestamp'2014-02-17 12:00:00' 
And M.Msg_ID IN ('90808','67678','534534')
ORDER by M.MSG_TS,p.payload_corl_id desc;
  

DatabaseUtility Request Internal 18-FEB-14 01.00.10.569000000 PM
  DatabaseUtility Response内部18-FEB-14 01.00.19.553000000 PM
  DatabaseUtility Request Internal 18-FEB-14 01.00.29.146000000 PM
  DatabaseUtility Response内部18-FEB-14 01.00.29.705000000 PM
  DatabaseUtility Request Internal 18-FEB-14 01.00.35.278000000 PM
  DatabaseUtility Response内部18-FEB-14 01.00.38.313000000 PM

1 个答案:

答案 0 :(得分:0)

select M.MSG_DESC
     , M.Msg_Ts 
     ,TIMESTAMPDIFF(SECOND, M.MSG_DESC, M.Msg_Ts )
from INTLOG.ESB_MSG_L M INNER JOIN INTLOG.ESB_PAYLOAD_L P
ON   M.MSG_ID = P.MSG_ID
WHERE
    M.Msg_Ts >= Timestamp'2014-02-16 00:00:00' 
And M.Msg_Ts <= Timestamp'2014-02-17 12:00:00' 
And M.Msg_ID IN ('90808','67678','534534')
ORDER by M.MSG_TS,p.payload_corl_id desc;