Sql 如何基于oracle中另一个表中的行值选择列

Sql 如何基于oracle中另一个表中的行值选择列,sql,oracle,Sql,Oracle,我有如下两张桌子。我想根据第一个表中行的值从第二个表中选择一列 table1 table2 id pos1 pos2 id1 id2 id3 position 41a1 A1T1 V1 1122 41a1 99a1 A1T1V1 1133 A1T1 V2 1133 41a2 99a2 A1T1

我有如下两张桌子。我想根据第一个表中行的值从第二个表中选择一列

table1 table2 id pos1 pos2 id1 id2 id3 position 41a1 A1T1 V1 1122 41a1 99a1 A1T1V1 1133 A1T1 V2 1133 41a2 99a2 A1T1V2 99a3 A1T1 V3 1144 41a3 99a3 A1T1V3 41a2 A1T1 V4 41a3 A1T1 V5 t2.id1 t2.id2或t2.id3基于if t1.id的值,类似于下面的if循环:

if t1.pos1 ='A1T1' and substr(t2.position,1,4)='A1T1' and substr(t1.id,1,2)='41' then t2.id2 elseif substr(t1,id,1,2)='99' then t2.id3 else t2.id1 如果t1.pos1='A1T1'和substr(t2.位置,1,4)='A1T1'和substr(t1.id,1,2)='41' 然后 t2.id2 埃尔塞夫 substr(t1,id,1,2)='99' 然后 t2.id3 其他的 t2.id1
听起来你想要一个
案例
语句

select t1.id,
       (case when t1.pos1 ='A1T1' 
              and substr(t2.position,1,4)='A1T1' 
              and substr(t1.id,1,2)='41' 
             then t2.id2
             when substr(t1,id,1,2)='99' 
             then t2.id3 
             else t2.id1 
         end)
   ...
select t1.id,
       (case when t1.pos1 ='A1T1' 
              and substr(t2.position,1,4)='A1T1' 
              and substr(t1.id,1,2)='41' 
             then t2.id2
             when substr(t1,id,1,2)='99' 
             then t2.id3 
             else t2.id1 
         end)
   ...