日期:2014-05-17  浏览次数:20885 次

sql语句优化
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

------解决方案--------------------
同一张表啊
不用这么复杂
用decode+sum就可以实现
------解决方案--------------------
探讨
同一张表啊
不用这么复杂
用decode+sum就可以实现