A表里aa字段的值是'a123',B表里bb字段的值是'a123,b456'或者'c789,d123'怎么写一个sql,取出A表里aa字段的值包含在B表里的bb字段中的所有记录

解决方案 »

  1.   


    select * from a, b
     where instr(',' || b.字段 || ',', 
                 ',' || a.字段 || ',' ) > 0;
      

  2.   

    select * from a, b
     where instr(',' || b.字段 || ',', 
                 ',' || a.字段 || ',' ) > 0;
      

  3.   

    with a as
    (select 'a123' aa from dual)
    ,b as
    (select 'a123,b456' bb from dual
    union all
    select 'c789,d123' from dual
    union all
    select 'a123,dadaf' from dual
    )select * from a,b where  bb like '%'||aa||'%'--result:a123 a123,b456
    a123 a123,dadaf
      

  4.   

    3楼这个把每行的值都写到sql里了,我的表里有200多行,我不可能这样写呀!其它人的回复,我都试了,多出来几百条数据。
    a表里有270行,我想保留a表所有值。b表符合条件的列出。