select tr.ri ,tr.rn,mo.oi
from aaaaa mo,bbbbb om,cccccc kcc,ddddd tr
where mo.ei='xxxxxx' and mo.ot=1
and mo.oi=om.doi(+) and om.ot=21
and om.oi=kcc.oi and kcc.ri=tr.ri and kcc.nf !=2cccccc kcc 这张表可能是空表 就查不出来数据 怎么解决? 标准sql怎么写?
where mo.ei='xxxxxx' and mo.ot=1 这个可以确定mo.oi 这个字段必须查出 不管其他表

解决方案 »

  1.   

    aaaaa mo,bbbbb om,cccccc kcc,ddddd tr
    这四张表mo.ei='xxxxxx' and mo.ot=1 可以确定mo的一条数据
    mo.oi=om.doi and om.ot=21 可以确定om的一条数据
    om.oi=kcc.oi 确定kcc的一条数据
    kcc.ri=tr.ri and kcc.nf !=2 确定tr的一条数据最后需要查出tr.ri ,tr.rn,mo.oi 这3个字段
    mo.oi 必须查出 另外两个可以空 
      

  2.   

    select tr.ri ,tr.rn,mo.oi
    from aaaaa mo,bbbbb om,cccccc kcc,ddddd tr
    where mo.ei='xxxxxx' and mo.ot=1
        and mo.oi=om.doi(+) and om.ot=21
        and om.oi=kcc.oi(+) and kcc.ri=tr.ri and kcc.nf !=2也是这个就行了and om.oi=kcc.oi(+)
      

  3.   

    om.oi=kcc.oi and kcc.nf !=2 确定kcc的一条数据 
    kcc.ri=tr.ri  确定tr的一条数据 
      

  4.   

    额,你不考虑cccccc,
    and om.oi=kcc.oi(+) 
    用个右连接。
      

  5.   

    不要看我顶楼的sql 看2楼的问题
      

  6.   

    select tr.RuleID RuleID,tr.RuleName RuleName,mo.ObjID ObjID 
    ManagedObj mo,ObjIDMap om,KPICollectCfg kcc,ThresholdRule tr
    where mo.EquipIP='192.168.0.116@SZX236' and mo.ObjType=1
    and mo.ObjID=om.DeviceObjID(+) 
    and om.ObjID=kcc.ObjID(+) and kcc.RuleID=tr.RuleID(+)
    这样可以查出一条数据
      

  7.   

    先做查询,再用结果集作连接。
    select a.name,b.sex,c.addr from aaaaa a ,(select * from bbbb where id='xx') b ,(select * from ccc where id='cc') c 
    where 表关联
      

  8.   

    select tr.ri ,tr.ri,mo.oi
    from aaaaa mo left join bbbbb om
    on mo.oi=om.doi and om.ot=21
    inner join ccccc kcc
    on om.oi=kcc.oi
    inner join ddddd tr
    on kcc.ri=tr.ri and kcc.nf!=2
    where mo.ei='xxxxxx' and mo.ot=1
      

  9.   

    错了
    select tr.ri ,tr.ri,mo.oi
    from aaaaa mo left join bbbbb om
    on mo.oi=om.doi and om.ot=21
    left join ccccc kcc
    on om.oi=kcc.oi
    left join ddddd tr
    on kcc.ri=tr.ri and kcc.nf!=2
    where mo.ei='xxxxxx' and mo.ot=1
      

  10.   

    想要的就是这种sql 可惜
    [SELECT - 0 row(s), 0.000 secs]  [Error Code: 933, SQL State: 42000]  ORA-00933: SQL 命令未正确结束
      

  11.   


    用left join就可以了。把tr.ri和tr.rn 都用left join来连接