有三张表分别如下:一: T_WORK_PLAN
    字段: 
          tsk 
二: VW_TSK
字段 
      tsk (PK )
     pro_code,(唯一)
     tsk_name, 
三: T_PROCESS_RESULT 
字段
      pro_code 其中 T_PROCESS_RESULT 要和T_WORK_PLAN 进行全外连接
所以借助于 VW_TSK 表请问这句SQL应该怎么写啊
  

解决方案 »

  1.   

    你先把1和2关联,再用3和这个结果关联。
    1和2的tsk是否一一对应你也没说??
      

  2.   

    select c.*,d.* from 
    (select a.* ,b.* from vw_tsk a , T_PROCESS_RESULT b where a.pro_code=b.pre_code) c  
    left outer join T_WORK_PLAN d 
     on c.tsk=d.tsk 
      

  3.   


    select t2.*
    from T_PROCESS_RESULT t1,
     (select a.tsk,b.*
       from VW_TSK a, T_PROCESS_RESULT b 
       where  a.pro_code=b.pro_code
     ) t2
    where t1.tsk=t2.tsk
      

  4.   

    楼上各位,LZ要的是full outer join
    而且select a.* ,b.* from ...这步就要保证是全外连接。
      

  5.   

    select c.*,d.* from 
    (select a.* ,b.* from vw_tsk a , T_PROCESS_RESULT b where a.pro_code=b.pre_code) c  
    left outer join T_WORK_PLAN d 
    on c.tsk=d.tsk 
      

  6.   

    太急了,没写  T_WORK_PLAN中的TSK是FK 参照 VW_TSK
      

  7.   

    给你写的例子:
    OPER@tl>select * from test;       AAA
    ----------
             2
             3OPER@tl>select * from test2;       AAA        BBB
    ---------- ----------
             2          2
             3          3OPER@tl>select * from test3;       BBB
    ----------
             1
             2OPER@tl>select c.aaa,d.*
      2  from (
      3  select a.aaa,b.bbb
      4  from test a,test2 b
      5  where a.aaa=b.aaa) c
      6  full outer join test3 d
      7  on (c.bbb=d.bbb);       AAA        BBB
    ---------- ----------
             2          2
             3
                        1
      

  8.   

    T_WORK_PLAN中的TSK是FK,但不一定与关联表完全相同,如果有缺的就先用个全外连接。
      

  9.   


    谢谢了哈哈.....SELECT  
    count(*)
    FROM
    T_WORK_PLAN a  FULL OUTER JOIN  VW_TSK c  ON(a.TSK = c.TSK) ,T_PROCESS_RESULT b
    where  b.proc_code = c.proc_code
    这个和你的有什么不同啊??
      

  10.   


    谢谢了哈哈.....SELECT  
    count(*)
    FROM
    T_WORK_PLAN a  FULL OUTER JOIN  VW_TSK c  ON(a.TSK = c.TSK) ,T_PROCESS_RESULT b
    where  b.proc_code = c.proc_code
    这个和你的有什么不同啊??