解决方案 »

  1.   

    列转行,再行转列,B表访问次数少了
    但是至于那个执行时间快,不确定,具体执行下或看一下执行计划吧
    SELECT MAX(DECODE(A.CONAME,'code1',B.codeName)),
         MAX(DECODE(A.CONAME,'code2',B.codeName)),
         MAX(DECODE(A.CONAME,'code3',B.codeName))
    FROM
       (select code1 as code,'code1' as colname,rowid as id from TABLEA
       union all
       select code2 as code,'code2' as colname,rowid as id from TABLEA
       union all
       select code3 as code,'code3' as colname,rowid as id from TABLEA) A,TABLEB B
    WHERE A.CODE=B.CODE
    GROUP BY A.ID
      

  2.   

    这很简单嘛,比如一个单据表有 批准人,审核人,复审核人而这些人肯定都是对应的员工表。那么查询的时候自然就要关联一下,只是这个sql关联的有些多了。
      

  3.   

    如果是这样的表,考虑一下改成由person_name,person_identity和document_id三个字段组成的表如何,类似的你的表也可以改改嘛。只是个想法,可以试试
      

  4.   

    b表很大吗?b.code应该有唯一索引的吧,这样应该问题也不大
      

  5.   


    select 
    (case when a.code1=b1.code then b1.codename end),
    (case when a.code1=b1.code then b1.codename end),
    (case when a.code1=b1.code then b1.codename end)
    from tabA a
    left join tabB b1
    on (a.code1=b1.code or a.code2=b1.code or a.code3= b1.code)
      

  6.   

    此方法不可取
    取出的结果会一条变三条,如
    C1NAME   NULL   NULL
    NULL   C2NAME   NULL
    NULL   NULL   C3NAME
      

  7.   

    此方法不可取
    取出的结果会一条变三条,如
    C1NAME   NULL   NULL
    NULL   C2NAME   NULL
    NULL   NULL   C3NAME
    select 
    (case when a.code1=b1.code then b1.codename end),
    (case when a.code2=b1.code then b1.codename end),
    (case when a.code3=b1.code then b1.codename end)
    from tabA a
    left join tabB b1
    on (a.code1=b1.code or a.code2=b1.code or a.code3= b1.code)
      

  8.   

    4楼的方法可以测一下,速度有没有提升.
    楼主原本的语句,如果每次经过where筛选后,数据量不大,在tabB的code上加个索引就差不多了
      

  9.   

    此方法不可取
    取出的结果会一条变三条,如
    C1NAME   NULL   NULL
    NULL   C2NAME   NULL
    NULL   NULL   C3NAME
    select 
    (case when a.code1=b1.code then b1.codename end),
    (case when a.code2=b1.code then b1.codename end),
    (case when a.code3=b1.code then b1.codename end)
    from tabA a
    left join tabB b1
    on (a.code1=b1.code or a.code2=b1.code or a.code3= b1.code)
    select max(case when a.code1=b.code then b.CODNAME end),
    max(case when a.code2=b.code then b.CODNAME end),
    max(case when a.code3=b.code then b.CODNAME end) from a left join b on a.code1=b.code or a.code2=b.code or a.code3= b.code
     group by a.rowid
      

  10.   


    --如果满足要求的话 楼主看看这个
    SELECT code1, code2, code3, wm_concat(t2.name)
      FROM t t1
      LEFT JOIN tb t2
        ON (t1.code1 = t2.code OR t1.code2 = t2.code OR t1.code3 = t2.code)
     GROUP BY code1, code2, code3