2016-12-26 70 views
0
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 

請問有人請幫忙我想知道時間requestid 1和156之間的區別?Oracle 10g知道一個表中兩行之間的時間差

我試過下面的查詢,但沒有得到正確的輸出。

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 

回答

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:

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