select dn,
node,
(select sum(a.clear_during)
from al_history a
where a.org_no = 65396
and a.dn = t.dn
and a.node = t.node) as Mains,
(select sum(b.clear_during)
from al_history b
where b.org_no = 65397
and b.dn = t.dn
and b.node = t.node) as DG,
(select sum(c.clear_during)
from al_history c
where c.org_no = 65398
and c.dn = t.dn
and c.node = t.node) as Battery
from al_history t
where (org_no = 65396)
or (org_no = 65397)
or (org_no = 65398)
group by t.dn, t.node
node,
(select sum(a.clear_during)
from al_history a
where a.org_no = 65396
and a.dn = t.dn
and a.node = t.node) as Mains,
(select sum(b.clear_during)
from al_history b
where b.org_no = 65397
and b.dn = t.dn
and b.node = t.node) as DG,
(select sum(c.clear_during)
from al_history c
where c.org_no = 65398
and c.dn = t.dn
and c.node = t.node) as Battery
from al_history t
where (org_no = 65396)
or (org_no = 65397)
or (org_no = 65398)
group by t.dn, t.node
解决方案 »
- 请高手帮忙写个oracle命令?跪求!
- vmware infrastructure client出现failed to power on:A general system error occurred
- 请教多表查询语句写法?
- ORA-01200错误如何恢复(高分在线等)
- 如何在oracle817中建立与SQLSERVER的DBLINK?
- Procedure 中如何将一个表的内容全部插入另一结构相同的表?
- 一个update语句,请大家看看
- 通过windows xp 的服务启动不了oracle数据库,只能让数据库进入已装载状态?
- 为什么启动sql plus时也不能登录?
- 请问怎样连接到manager server?
- ms sql的条件判断语句转换为oracle的
- 在问oracle 服务启动问题,麻烦大家解决一下
不用这么复杂
用decode+sum就可以实现
SUM(DECODE(ORG_NO, 65397, CLEAR_DURING)) DG,
SUM(DECODE(ORG_NO, 65398, CLEAR_DURING)) BATTERY,
FROM AL_HISTORY
WHERE ORG_NO IN (65396, 65397, 65398)
GROUP BY T.DN, T.NODE;