左连接那里怎么改写select a.deviceid,
       a.assetname,
       a.devicemodelid,
       b.assettype,
       a.rackid,
       a.roomid,
       nvl(a.ustart, 0) as ustart,
       nvl(b.uheigh, 0) as uheigh,
       (uheigh + ustart) as ustop,
       a.utotal,
       a.principal,
       c.branchid,
       c.branch as branchname,
       d.devicetypeid,
       d.devicetype,
       e.devicetoptype as devicetoptypeid,
       e.devicetop as devicetoptype
  from t_devices a, t_devicemodel b, t_branch c,t_devicetype d,t_devicetoptype e
 where a.devicemodelid = b.devicemodelid
   and to_number(trim(a.branchid)) = c.branchid(+)
   and b.devicetypeid=d.devicetypeid
   and d.devicetoptype=e.devicetoptype

解决方案 »

  1.   

    NVL->IFNULL()
    有内连接、左连接
    from t_devices a, t_devicemodel b, ,t_devicetype d,t_devicetoptype e 
    left join t_branch c
    on
    to_number(trim(a.branchid)) = c.branchid(+) where a.devicemodelid = b.devicemodelid 
      
      and b.devicetypeid=d.devicetypeid 
      and d.devicetoptype=e.devicetoptype
      

  2.   

    去掉(+),连接部份已经出来了,
    NVL->IF F1 IS NULL
      

  3.   

    nvl(a.ustart, 0) as ustart,->
    CASE WHEN a.ustart IS NULL THEN 0 ELSE a.ustart END
      

  4.   

    nvl -->ifnull
    to_number(trim(a.branchid)) = c.branchid(+) -->此为左联接,用left join替换
    to_number函数不知道有没有,如果是mysql,可以用 "to_number(trim(a.branchid))" --> cast(trim(a.branchid) as unsigned int)
      

  5.   

    改成这样select a.deviceid,
           a.assetname,
           a.devicemodelid,
           b.assettype,
           a.rackid,
           a.roomid,
           COALESCE(a.ustart, (0)::numeric) AS ustart,
           COALESCE(b.uheigh, (0)::numeric) as uheigh,
           (uheigh + ustart) as ustop,
           a.utotal,
           a.principal,
           c.branchid,
           c.branch as branchname,
           d.devicetypeid,
           d.devicetype,
           e.devicetoptype as devicetoptypeid,
           e.devicetop as devicetoptype
      from t_devices a, t_devicemodel b,t_devicetype d,t_devicetoptype e
      left join t_branch c 
    on to_number(trim(a.branchid)) = c.branchid
     where a.devicemodelid = b.devicemodelid
       and b.devicetypeid=d.devicetypeid
       and d.devicetoptype=e.devicetoptype不对
    [Err] ERROR:  invalid reference to FROM-clause entry for table "a" at character 595
    HINT:  There is an entry for table "a", but it cannot be referenced from this part of the query.
      

  6.   

    select a.deviceid, 
          a.assetname, 
          a.devicemodelid, 
          b.assettype, 
          a.rackid, 
          a.roomid, 
          COALESCE(a.ustart, (0)::numeric) AS ustart, 
          COALESCE(b.uheigh, (0)::numeric) as uheigh, 
          (uheigh + ustart) as ustop, 
          a.utotal, 
          a.principal, 
          c.branchid, 
          c.branch as branchname, 
          d.devicetypeid, 
          d.devicetype, 
          e.devicetoptype as devicetoptypeid, 
          e.devicetop as devicetoptype 
      from t_devices a
    inner join t_devicemodel b on a.devicemodelid = b.devicemodelid 
    inner join t_devicetype d on b.devicetypeid=d.devicetypeid 
    inner join t_devicetoptype e on d.devicetoptype=e.devicetoptype
    left join t_branch c on to_number(trim(a.branchid)) = c.branchid 
      

  7.   

    select a.deviceid, 
      a.assetname, 
      a.devicemodelid, 
      b.assettype, 
      a.rackid, 
      a.roomid, 
      COALESCE(a.ustart, (0)::numeric) AS ustart, 
      COALESCE(b.uheigh, (0)::numeric) as uheigh, 
      (uheigh + ustart) as ustop, 
      a.utotal, 
      a.principal, 
      c.branchid, 
      c.branch as branchname, 
      d.devicetypeid, 
      d.devicetype, 
      e.devicetoptype as devicetoptypeid, 
      e.devicetop as devicetoptype 
    from (((t_devices a inner join t_devicemodel b on a.devicemodelid = b.devicemodelid )
    inner join t_devicetype d on b.devicetypeid=d.devicetypeid)
    inner join t_devicetoptype e on d.devicetoptype=e.devicetoptype)
    left join t_branch c on to_number(trim(a.branchid)) = c.branchid