关于Oracle中left join简写写法在多条件时如何使用

temptester 2013-08-20 06:41:23
select count(1)
from t_im_moveissuebill a
left join t_im_moveissuebillentry b
on a.fid = b.fparentid
left join t_bot_relation r
on a.fid = r.fsrcobjectid
left join t_im_moveinwarehsbillentry ib
on r.fdestobjectid = ib.fparentid
and b.fmaterialid = ib.fmaterialid
and b.fassistpropertyid = ib.fassistpropertyid
where to_char(A.Fbizdate, 'yyyy-mm-dd') >= '2013-08-01' and
to_char(A.Fbizdate, 'yyyy-mm-dd') <= '2013-08-15' and exists
(select 1 from TT_WHEREVALUES W where W.FID = B.FWAREHOUSEID)
and NVL(A.FAUDITORID, ' ') <> ' '
and NVL(A.FIsInitBill, 0) = 0

以上的写法我获得的行数结果是9457.
下边的写法获得的行数结果是9331.
select count(1)
from t_im_moveissuebill a,
t_im_moveissuebillentry b,
t_bot_relation r,
t_im_moveinwarehsbillentry ib
where a.fid = b.fparentid
and to_char(A.Fbizdate, 'yyyy-mm-dd') >= '2013-08-01'
and to_char(A.Fbizdate, 'yyyy-mm-dd') <= '2013-08-15'
and exists
(select 1 from TT_WHEREVALUES W where W.FID = B.FWAREHOUSEID)
and NVL(A.FAUDITORID, ' ') <> ' '
and NVL(A.FIsInitBill, 0) = 0
and a.fid = r.fsrcobjectid(+)
and r.fdestobjectid = ib.fparentid(+)
and b.fmaterialid = ib.fmaterialid
and b.fassistpropertyid = ib.fassistpropertyid
那么像上一段的多条件的left join在简写时,应该如何在where后边编写呢??
...全文
2428 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
无敌小二傻 2013-09-11
  • 打赏
  • 举报
回复
引用 楼主 u011759964 的回复:
select count(1)
  from t_im_moveissuebill a
  left join t_im_moveissuebillentry b
    on a.fid = b.fparentid
  left join t_bot_relation r
    on a.fid = r.fsrcobjectid
  left join t_im_moveinwarehsbillentry ib
    on r.fdestobjectid = ib.fparentid
   and b.fmaterialid = ib.fmaterialid
   and b.fassistpropertyid = ib.fassistpropertyid
 where to_char(A.Fbizdate, 'yyyy-mm-dd') >= '2013-08-01' and
  to_char(A.Fbizdate, 'yyyy-mm-dd') <= '2013-08-15' and exists
  (select 1 from TT_WHEREVALUES W where W.FID = B.FWAREHOUSEID)
    and NVL(A.FAUDITORID, ' ') <> ' '
    and NVL(A.FIsInitBill, 0) = 0
以上的写法我获得的行数结果是9457. 下边的写法获得的行数结果是9331.
select count(1)
  from t_im_moveissuebill         a,
       t_im_moveissuebillentry    b,
       t_bot_relation             r,
       t_im_moveinwarehsbillentry ib
 where a.fid = b.fparentid
   and to_char(A.Fbizdate, 'yyyy-mm-dd') >= '2013-08-01'
   and to_char(A.Fbizdate, 'yyyy-mm-dd') <= '2013-08-15'
   and exists
 (select 1 from TT_WHEREVALUES W where W.FID = B.FWAREHOUSEID)
   and NVL(A.FAUDITORID, ' ') <> ' '
   and NVL(A.FIsInitBill, 0) = 0
   and a.fid = r.fsrcobjectid(+)
   and r.fdestobjectid = ib.fparentid(+)
   and b.fmaterialid = ib.fmaterialid
   and b.fassistpropertyid = ib.fassistpropertyid
那么像上一段的多条件的left join在简写时,应该如何在where后边编写呢??
select count(1) from t_im_moveissuebill a, t_im_moveissuebillentry b, t_bot_relation r, t_im_moveinwarehsbillentry ib where a.fid = b.fparentid(+) and to_char(A.Fbizdate, 'yyyy-mm-dd') >= '2013-08-01' and to_char(A.Fbizdate, 'yyyy-mm-dd') <= '2013-08-15' and exists (select 1 from TT_WHEREVALUES W where W.FID = B.FWAREHOUSEID) and NVL(A.FAUDITORID, ' ') <> ' ' and NVL(A.FIsInitBill, 0) = 0 and a.fid = r.fsrcobjectid(+) and r.fdestobjectid = ib.fparentid(+) and b.fmaterialid = ib.fmaterialid(+) and b.fassistpropertyid = ib.fassistpropertyid(+)
幕幕 2013-09-10
  • 打赏
  • 举报
回复
简写可以写成:where table1.col(+) = table2.col;两条记录结果不一样也许是因为左连接保留了左边表的所有数据,虽然这些数据不符合要求
u010412956 2013-08-29
  • 打赏
  • 举报
回复
推荐第一种写法 第二种写法肯定不会等价,很多关联条件没有外连接起来
gingerkang 2013-08-29
  • 打赏
  • 举报
回复
(+)= =(+)
zhaolushuan 2013-08-28
  • 打赏
  • 举报
回复
这个表 t_im_moveissuebill 加上你的限定条件是你查出的条数 后面的那个 a.fid = b.fparentid你做了关联 等于加了限定条件 所以会少些
我刚睡醒 2013-08-28
  • 打赏
  • 举报
回复
问题好像出在t_im_moveinwarehsbillentry ib表 你第一个sql语句用left关联t_im_moveinwarehsbillentry时根本不起作用,查出的数据以t_im_moveissuebill a加where为主。第二个sql中就关联上了t_im_moveinwarehsbillentry表
chenbest111 2013-08-26
  • 打赏
  • 举报
回复
没有数据结构,没有说明,谁看都蛋疼
temptester 2013-08-26
  • 打赏
  • 举报
回复
这么蛋疼。就没有个人来解答么

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧