select a.jgbh,a.jgmc,a.jgdm,a.jgjb,
       (select nvl(count(*),0) as xlzs from t_sc_sbzb where jgbh=a.jgbh and sjsbid='XLZXL'
        and dydjid='8c196deec1e6446db45b41107b9c924c') as xlzs, --1.188
        
       (select nvl(count(*),0) as sl from t_sys_jgb jgb,t_sc_sbzb sb,t_sc_pdsb_pjmx_xl xl 
where jgb.jgbh=sb.jgbh and sb.sbid=xl.sbid and to_char(xl.pdrq,'yyyy')='2007' 
and jgb.jgbh=a.jgbh and xl.xldy='10KV' ) as xlpj,--1.687
        
       (select nvl(count(*),0) as sl from t_sys_jgb jgb,t_sc_sbzb sb,t_sc_pdsb_pjmx_xl xl 
where jgb.jgbh=sb.jgbh and sb.sbid=xl.sbid and to_char(xl.pdrq,'yyyy')='2007' 
and jgb.jgbh=a.jgbh and xl.xlpddj='一类设备' and xl.xldy='10KV') as xlpj1,  --2.922 
        
        (select nvl(sum(gt.dj),0)/1000 as xlzcd from t_sc_sbzb sb,t_sc_sbzb sb1,t_sc_gtxx gt,
          t_sys_jgb jgb,t_sc_xl xl
          where sb.jgbh=jgb.jgbh and sb.sbid=sb1.sjsbid and sb1.sbid=gt.sbid and sb.sbid=xl.sbid
           and jgb.jgbh=a.jgbh and sb.sbzt='运行' and sb.dydjid='8c196deec1e6446db45b41107b9c924c' 
          )+                 --2.485
         (select nvl(sum(pds.dj),0)/1000 as xlzcd from t_sc_sbzb sb,t_sc_pds pds,t_sys_jgb jgb 
         where jgb.jgbh=sb.jgbh and sb.sbid=pds.sbid and jgb.jgbh=a.jgbh and sb.sbzt='运行' 
         and sb.dydjid='8c196deec1e6446db45b41107b9c924c' )
         as xlzcd,  --1.162         from t_sys_jgb a
where a.state='有效' and a.jgbm<>'变电站级' and   a.xjjgbhc like'%da342c926f264fb0bacfc5c2f68db271%'  --25.203
      and jgjb<=3 order by a.jgjb如题:这种类型的SQL语句,有没有好的方法能提高查询速度,

解决方案 »

  1.   

    好长的句子,还有错误。赫赫。
    看了一下,只能说,
    可以的话,把相同的表的抽取,合并起来,不抽取两次。会比你现在的做法快一些。比如,第一个合计,第4个合计,第5个合计,就可以合并。形成第一个新的结果集。
    第二个合计,第三个合计可以合并。形成第二个新的结果集。合并方式,
    select sum(decode(f1,'Y',1,0)),sum(decode(f1,'N',1,0)) from .....可以使用sum,以及decode或者case之类来做到。对第一个,第二个新的结果集取数据。
      

  2.   

    先谢谢了~    你说的合并方式,都是使用的,sum()  那sum()能和count(*) 一起使用嘛。我也没法试,今天在网吧上的,上班了去试试。
         你说的错误是最后","号哇,主要是下面还有好几条,都是类式的,我就没有放上来了哈