各位大虾:
    谁能帮小弟优化一下这个sql啊,sf02表的数据在七千万左右,sf01表的数据在三千万左右,感激不尽:
select a.tcol2, a.departcode, a.sendtime, sum(a.mainamount) mainamount
  from sf02 a
 where a.ksdm = '11019204'
   and exists
 (select policyno
          from sf01 b
         where b.businessnature = '531'
            union all select policyno from sf01 b where b.businessnature = '532'
           and a.policyno = b.policyno)
   and (a.kindcode = 'R21' or a.kindcode = 'R29')
   and a.insert_time <= to_date('2011-09-05', 'yyyy-MM-dd')
   and a.insert_time >= to_date('2000-08-25', 'yyyy-MM-dd')
 group by a.tcol2, a.departcode, a.sendtime 

解决方案 »

  1.   

    SQL优化问题最好提建表脚本和inser示例语句,或者 with语句1、sf02 表按照insert_time字段建立分区
    2、sf01 表businessnature加索引没啊?晕,啥都看不出来,你提供的东西太少了。
      

  2.   

    首先感谢sotom的回复
    sf01表businessnature的已经有索引,sf02表的几个字段也存在索引
    至于分区,由于数据库是分公司的,我们好像是没有权限,如果但看这个SQL的话,是否还有优化的空间?