Oracle 10g知道一个表中两行之间的时差

时间:2016-12-26 17:25:48

标签: oracle-sqldeveloper

requestid   Date
2   12/22/2016 23:21
3   12/22/2016 23:21
1   12/22/2016 23:21
37  12/22/2016 23:20
156 12/22/2016 23:20

有人可以帮助我想知道时间1和156之间的差异吗?

我已尝试过以下查询但未获得正确的输出。

 Select A.IFCOMPONENTUID,A.FPROCSTAGESTARTDT, (A.FPROCSTAGESTARTDT - B.FPROCSTAGESTARTDT) AS timedifference from XA_CASA.CFX_FILE_PROC_STAT A
where INNER JOIN XA_CASA.CFX_FILE_PROC_STAT B On A.IFCOMPONENTUID = (B.IFCOMPONENTUID + 155)  and 
 order by FILERUNTIMEUID desc

1 个答案:

答案 0 :(得分:0)

类似于你的构造...

SELECT
    A.IFCOMPONENTUID,
    A.FPROCSTAGESTARTDT,
    B.IFCOMPONENTUID CompareID
    (A.FPROCSTAGESTARTDT - B.FPROCSTAGESTARTDT) TimeDiff
FROM XA_CASA.CFX_FILE_PROC_STAT A
INNER JOIN XA_CASA.CFX_FILE_PROC_STAT B
    ON A.IFCOMPONENTUID = (B.IFCOMPONENTUID + 155)
WHERE A.IFCOMPONENTUID = 1

我希望在where子句中使用显式ID,以便更灵活地更改ID:

SELECT
    A.IFCOMPONENTUID,
    A.FPROCSTAGESTARTDT,
    B.IFCOMPONENTUID CompareID,
    (A.FPROCSTAGESTARTDT - B.FPROCSTAGESTARTDT) TimeDiff
FROM XA_CASA.CFX_FILE_PROC_STAT A
INNER JOIN XA_CASA.CFX_FILE_PROC_STAT B
    ON 1 = 1
WHERE A.IFCOMPONENTUID = 1
    AND B.IFCOMPONENTUID = 156