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
10 个解决方案
#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
有内连接、左连接
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
能帮我写完整嘛 怎么还有 (+)
#3
去掉(+),连接部份已经出来了,
NVL->IF F1 IS NULL
NVL->IF F1 IS NULL
#4
越来糊涂 就不能写个完整的
#5
nvl(a.ustart, 0) as ustart,->
CASE WHEN a.ustart IS NULL THEN 0 ELSE a.ustart END
CASE WHEN a.ustart IS NULL THEN 0 ELSE a.ustart END
#6
还是不对
#7
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)
to_number(trim(a.branchid)) = c.branchid(+) -->此为左联接,用left join替换
to_number函数不知道有没有,如果是mysql,可以用 "to_number(trim(a.branchid))" --> cast(trim(a.branchid) as unsigned int)
#8
改成这样
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.
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.
#9
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
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
#10
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
#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
有内连接、左连接
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
能帮我写完整嘛 怎么还有 (+)
#3
去掉(+),连接部份已经出来了,
NVL->IF F1 IS NULL
NVL->IF F1 IS NULL
#4
越来糊涂 就不能写个完整的
#5
nvl(a.ustart, 0) as ustart,->
CASE WHEN a.ustart IS NULL THEN 0 ELSE a.ustart END
CASE WHEN a.ustart IS NULL THEN 0 ELSE a.ustart END
#6
还是不对
#7
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)
to_number(trim(a.branchid)) = c.branchid(+) -->此为左联接,用left join替换
to_number函数不知道有没有,如果是mysql,可以用 "to_number(trim(a.branchid))" --> cast(trim(a.branchid) as unsigned int)
#8
改成这样
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.
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.
#9
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
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
#10
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