select t.company company, 
      t.syncdomain syncdomain,
      
      sum(case when t.subchannel_1 > 0 or t.subchannel_2 > 0 or t.subchannel_3 > 0 or t.subchannel_4 > 0 or t.subchannel_5 > 0 or t.subchannel_6 > 0 or t.subchannel_7 > 0 or t.subchannel_8 > 0 then 1 else 0 end) subchannel,
      (nvl(sum(t.basesalary), 0) + nvl(sum(t.posisalary), 0) +
      nvl(sum(t.perfsalary), 0) + nvl(sum(t.assisalary), 0) +
      nvl(sum(t.overtimesalary), 0) + nvl(sum(t.othersalary), 0) +
      nvl(sum(t.bonus), 0)) sumvalue,
                     
      (nvl(sum(t.basesalary), 0) + nvl(sum(t.posisalary), 0) +
      nvl(sum(t.perfsalary), 0) + nvl(sum(t.assisalary), 0)) wage,
                     
      (nvl(sum(t.overtimesalary), 0) + nvl(sum(t.othersalary), 0) +
      nvl(sum(t.bonus), 0)) prize 
                     
      from emp_sala_safe_annu_syn t,   --此表中数据有八百多万
      (select c.id from org_company_syn c where c.validto > sysdate and c.activeflag = 1 start with c.id = '3' connect by prior c.id = c.parent) c, --这一条语句最好不要变
      Bi_Empinfo bi   --此表数据八十多万
      where t.company = c.id 
      and t.employee = bi.employee 
      and t.year = '2011' 
      and t.month in (1)
      group by t.company, t.syncdomain
----我用到了emp_sala_safe_annu_syn 表中的年和月 联合索引 建了个syncdomain
索引没用上   Bi_Empinfo也有索引 但似乎都没用上  执行计划显示耗费57947    执行出来结果需要2到三分钟不等  月份多的话可能更久

解决方案 »

  1.   

     t.company, t.syncdomain 瓶颈在这里,这里消耗大。
    注意,from 后面大表在前面,where后能过滤大量数据的条件在最后
      

  2.   

    1你要是能够先整理下t表的数据该多好啊
    把为null的先初始化0   
    所有的nvl都去掉了2  and t.year = '2011'  
      and t.month in (1)
    时间到底是字符还是数字  别让数据库自己做转换啦3好像看到bi表格了 呵呵  如果查询实在多  考虑做个中等粒度的聚合表吧
      

  3.   

    select 
         t.company company 
        ,t.syncdomain syncdomain
        ,sum(case wehn t.subchannel_1
                   +t.subchannel_2 
                   +t.subchannel_3
                   +t.subchannel_4
                   +t.subchannel_5
                   +t.subchannel_6
                   +t.subchannel_7
                   +t.subchannel_8
               then 1 else 0 
           end) subchannel
       ,nvl(sum(t.basesalary+t.posisalary+t.perfsalary+t.assisalary+t.overtimesalary+t.othersalary+t.bonus,0) sumvalue
       ,(nvl(sum(t.basesalary+t.posisalary+t.perfsalaryt.assisalary), 0) wage
       ,nvl(sum(t.overtimesalaryt.othersalary+t.bonus), 0) prize  
      from emp_sala_safe_annu_syn t, --此表中数据有八百多万
      (select c.id from org_company_syn c where c.validto > sysdate and c.activeflag = 1 start with c.id = '3' connect by prior c.id = c.parent) c, --这一条语句最好不要变
      Bi_Empinfo bi --此表数据八十多万
      where t.company = c.id  
      and t.employee = bi.employee  
      and t.year = '2011'  
      and t.month in (1)
      group by t.company, t.syncdomain
      

  4.   

    ,sum(case wehn t.subchannel_1
      +t.subchannel_2  
      +t.subchannel_3
      +t.subchannel_4
      +t.subchannel_5
      +t.subchannel_6
      +t.subchannel_7
      +t.subchannel_8
      >=1
      then 1 else 0  
      end) subchannel
    忘记写>=1了
      

  5.   

    索引,我是这么理解的。
    比如说我们查字典的时候,怎么才能快速查找到自己想要的汉字呢?大概有以下几种:
    1,按照字典一页一页查,
    2,按照字典前面的导航页,也就是字母顺序来查,
    3,通过偏旁部首来查,
    4,通过相关的或相近的字来查。其实上面这些就是索引的体现,所以我们买书的时候,一般书的前面都会有一页叫做索引页。然后,我们再说那些列应该建立索引,那么情况下我们不应该建立索引,因为索引只有建的适当才能真正提高效率,如果建的不对,不但不会提高效率,甚至有可能死锁等发生。
    应该建立索引:
    1,经常需要搜索的列。
    2,作为主键的列,
    3,经常用于与其他表进行连接的列上,一般都是外键。
    4,需要范围搜索的列。
    5,需要排序的列,order by
    6,where语句中常用判断的列。不应该创建索引的列:
    1,很少检索的列。
    2,只是用来参考的列。
    3,对于一些区分的列,比如性别什么的,只有0和1这样的值,没有必要。
    4,大数据类型的列,clob等。
    5,经常用于更新的列,因为修改性能和检索性能是相互制约的,当修改更多的时候,如果建立索引会导致修改性能降低。另外,还有一些习惯性的用法可能会导致索引无法被利用:
    1,不等于号(<>  !=),应修改为or连接的>和<的分别判断。
    2,is null 或 is not Null
    3,对列使用函数,例如:to_date(),trunc(),正确的写法应该把这些函数用于对面的数值。
    4,不匹配的类型不要做比较,例如字符型和数值型,因为oracle会自动使用函数进行类型转换。索引的东西真的很多很多,只能多尝试,多学习,想把索引用好很难的!