如不考虑效率,可以用一个sql实现
select b.b1, b.b2, b.b3
    from (select decode(a3, '1','%1', '2','20', '3','31', '4','41', 'xx') newa3
              from a
              where a.a1='IP' and a.a2='IP地址') a,
         (select b.b1, b.b2, b.b3,
                 decode(b1, '55','41', '45','31', '32','20', '23','20', '01') newb1
              from b) b
     where b.newb1 like a.newa3;
或者
select b.b1, b.b2, b.b3
    from a, b
    where (a.a1='IP' and a.a2='IP地址')
      and (  (a.a3='1' and b.b1 not in ('32','23'))
           or(a.a3='2' and b.b1 in ('32','23'))
           or(a.a3='3' and b.b1='45')
           or(a.a3='4' and b.b1='55') )

解决方案 »

  1.   

    select * from b where 
    (select a3 from a where a1='ip' and a2='地址')='1' and b1 not in ('32','33')
    union
    select * from b where 
    (select a3 from a where a1='ip' and a2='地址')='2' and b1 in ('32','33')
    union
    select * from b where 
    (select a3 from a where a1='ip' and a2='地址')='3' and b1='45'
    union
    select * from b where 
    (select a3 from a where a1='ip' and a2='地址')='4' and b1='55'
      

  2.   

    你的要求肯定不能用一个sql完成的
    写存储过程吧
      

  3.   

    select * from b
    where (exists(select 1 from a where a1='IP' and a2='客户端ip地址' and a1= '1') and b1 not in ('32','23'))
    or (exists(select 1 from a where a1='IP' and a2='客户端ip地址' and a1= '2') and b1 in ('32','23'))
    or (exists(select 1 from a where a1='IP' and a2='客户端ip地址' and a1= '3') and b1 in ('45'))
    or (exists(select 1 from a where a1='IP' and a2='客户端ip地址' and a1= '4') and b1 in ('55'))