第一个语句先执行外联接
再使用 
and sp.spec_prpty_id = '12'
and b.no_flag = 'A'
筛选
第二个语句先筛选,在外联接执行顺序不同导致的结果不一致

解决方案 »

  1.   

    明白了。。那怎么才可以让第一个sql查出来和第二个一样的结果呢。。必须用子查询么。。
      

  2.   

    使用left join on的结构然后把这两个条件也写到on的条件里
      

  3.   

    select w.wo_nbr, a.spec_prpty_value
      from cidp_hnwfm_user.wo w
      left join cidp_hnwfm_user.so_main_prod b on (w.so_nbr = b.so_nbr
                                                  and b.no_flag = 'A'), cidp_hnwfm_user.so_main_prod b
      left join cidp_hnwfm_user.so_main_prod_prpty a on (b.so_main_prod_id =
                                                        a.so_main_prod_id and
                                                        a.spec_prpty_id = '12')
    where 
     w.wo_type = 'N'
     and w.work_mode = 'M'
     and w.compl_date between trunc(sysdate - 1) and
     trunc(sysdate + 1) - 1 / 24 / 60 / 60;这样好像不对
      

  4.   

    select w.wo_nbr,a.spec_prpty_value
    from cidp_hnwfm_user.wo w
    left join
      cidp_hnwfm_user.so_main_prod b
    on w.so_nbr = b.so_nbr
    left join
      cidp_hnwfm_user.so_main_prod_prpty a
    on b.so_main_prod_id = a.so_main_prod_id
       and a.spec_prpty_id = '12'
       and b.no_flag = 'A'
    where w.compl_date between trunc(sysdate-1) and trunc(sysdate+1)-1/24/60/60