2014-05-20 15 views
0

我必須找出輸出文件名相對於輸入文件名查找相對於輸出文件輸入文件:SQL從表

select sourceid as RawFile, destinationid from audittraillogentry 
where event ='67' 
    and innodename like '%_SFTP_%'; 

       rawfile    |    destinationid 
------------------------------------+-------------------------------------------- 
shortcodes_cdr_20140202_161239.csv | coll_DefaultCollectorGroup_0_1400591981_13 

在我上面的輸入文件名稱提到的查詢結果是shortcodes_cdr_20140202_161239.csv(這可能是多個文件&我需要找到輸出的所有文件)

現在基於上述查詢的destinationid我發現的中間源ID

select sourceid, destinationid from audittraillogentry 
where event ='80' 
    and innodename like '%_SFTP_%' 
    and sourceid = 'coll_DefaultCollectorGroup_0_1400591981_13'; 

        sourceid     |    destinationid 
--------------------------------------------+--------------------------------------------- 
coll_DefaultCollectorGroup_0_1400591981_13 | proc_DefaultCollectorGroup_0_1400591981_120 

現在根據這個結果,我得到這樣

select destinationid 
from audittraillogentry 
where event ='68' 
    and sourceid = 'proc_DefaultCollectorGroup_0_1400591981_120'; 

喜歡我需要找到相對於所有的輸入輸出文件的輸出文件的目標ID文件&我想知道如何做到這一點,任何人都可以幫助我,這將是一個很大的幫助提前

感謝

回答

0

認爲三個查詢爲三個查詢了三名不同表,那麼你只需要加入日em(...據我瞭解您的要求)。像這樣的東西可能是你在找什麼:

select e68.destinationid 
from audittraillogentry e68, 
    audittraillogentry e80, 
    audittraillogentry e67 
where e67.event='67' 
    and e67.innodename like '%_SFTP_%' 
    and e67.destinationid=e80.sourceid 
    and e80.event='80' 
    and e80.innodename like '%_SFTP_%' 
    and e80.destinationid=e68.sourceid 
    and e68.event='68'; 

小提琴here

如果您需要這麼做的話,視圖確實很方便 - 例如,常見事件類型的視圖。

+0

謝謝wwkudu,我已經找到了相同的答案,反正非常感謝:) – Khanjarrr