从连接中获取数据需要其他条件

时间:2015-06-25 22:08:02

标签: sql db2-400

我还需要从referrf引入另一个数据,但不确定如何执行此操作。我也需要所有的行 来自astdta.referrf,其中RFCAT =' 8799'和RFSQ2 =' 1'然后给我们列RFSLC - 如果我添加这个我得不到结果> 和T02.rfcat =' 8799'

CREATE VIEW rklib.CLSPAYTPP AS
    SELECT ALL 
         T01.OTCOM#, T01.OTORD#,                                                                 
         t01.ottRND, T01.OTTRT,                                             
         T01.OTUSRN, T01.OTTRNC, T01.OHPTTC, T01.OHSLR#, 
         t01.OHORDT,                                                           
         T01.OHORDD, T01.OHTTN$, T02.RFCAT, T02.RFSLC, T02.RFSQ2,                                                                     
         t02.RFDTA                                                                  
    FROM ASTDTA.CLSPAYT2 T01 INNER JOIN
         ASTDTA.REFERRF T02
         ON T01.OTTRNC = T02.RFSLC WHERE RFCAT = '5058' AND RFSQ2 = '1'  

1 个答案:

答案 0 :(得分:1)

我认为你可以使用IN子句:

CREATE VIEW rklib.CLSPAYTPP AS
    SELECT ALL 
         T01.OTCOM#, T01.OTORD#,                                                                 
         t01.ottRND, T01.OTTRT,                                             
         T01.OTUSRN, T01.OTTRNC, T01.OHPTTC, T01.OHSLR#, 
         t01.OHORDT,                                                           
         T01.OHORDD, T01.OHTTN$, T02.RFCAT, T02.RFSLC, T02.RFSQ2,                                                                     
         t02.RFDTA                                                                  
    FROM ASTDTA.CLSPAYT2 T01 INNER JOIN
         ASTDTA.REFERRF T02
         ON T01.OTTRNC = T02.RFSLC WHERE RFCAT IN ('5058','8799') AND RFSQ2 = '1'