1.需求如图;2. 貌似图挂了:
表1:编码,数量1,金额1
表2:编码,数量2,金额2
表3:编码,数量3,金额3
-----最后我想要的结果是:  编码    数量1    金额1    数量2   金额2    数量3   金额3
 把这些字段按照列输出,当三个表的编码相等时,显示的一行上。
例,表1中的编码 ,表2和表3不存在 ,
则显示 为: 编码   数量1   金额1    0   0   0   0

解决方案 »

  1.   

    求大神给个思路。我现在表1  表2  表3 都是我在存储过程中通过with  as出来的表
      

  2.   

    只是个外关联吗?
    with taba ("编码","数量1","金额1")
    as
    (
    select 1,11,111  from dual union all 
    select 2,22,222  from dual union all 
    select 3,33,333  from dual 
    ),tabb ("编码","数量2","金额2")
    as
    (
    select 1,11,111  from dual union all 
    select 2,22,222  from dual 
    ),tabc ("编码","数量3","金额3")
    as
    (
    select 1,11,111  from dual 
    )
    select a."编码",
           a."数量1",
           nvl(a."金额1", 0),
           nvl(b."数量2", 0),
           nvl(b."金额2", 0),
           nvl(c."数量3", 0),
           nvl(c."金额3", 0)
      from taba a, tabb b, tabc c
     where a."编码" = b."编码"(+)
       and a."编码" = c."编码"(+)
      

  3.   

    with taba ("编码","数量1","金额1")
    as
    (
    select 1,11,111   union all 
    select 2,22,222   union all 
    select 3,33,333  
    ),tabb ("编码","数量2","金额2")
    as
    (
    select 1,11,111   union all 
    select 2,22,222   
    ),tabc ("编码","数量3","金额3")
    as
    (
    select 1,11,111  
    )SELECT  *
    FROM    taba
            LEFT JOIN tabb ON tabb.编码 = taba.编码
            LEFT JOIN tabc ON tabc.编码 = taba.编码