问题是这样的:我们秒数据表分区是按每天分区的 现在报表显示的时间比较慢,想优化一下 SQL如下:
select 
       ROUND(nvl(sum(case  when to_number(speed) <= 20  then  1  else   0   end),0)/(case when count(*)=0 then 1 else  count(*) end)*100,2)  speeding_0_20,
       ROUND(nvl(sum(case  when to_number(speed) > 20 and to_number(vehicle_speed) <= 40 then  1  else  0 end),0)/(case when count(*)=0 then 1 else  count(*) end)*100,2) speeding_20_40,
       ROUND(nvl(sum(case  when to_number(speed) > 40 and to_number(vehicle_speed) <= 60 then  1  else  0 end),0)/(case when count(*)=0 then 1 else  count(*) end)*100,2) speeding_40_60,
       ROUND(nvl(sum(case  when to_number(speed) > 60 and to_number(vehicle_speed) <= 70 then  1  else  0 end),0)/(case when count(*)=0 then 1 else  count(*) end)*100,2) speeding_60_70,
       ROUND(nvl(sum(case  when to_number(speed) > 70 and to_number(vehicle_speed) <= 80 then  1  else  0 end),0)/(case when count(*)=0 then 1 else  count(*) end)*100,2) speeding_70_80,
       ROUND(nvl(sum(case  when to_number(speed) > 80 and to_number(vehicle_speed) <= 90 then  1  else  0 end),0)/(case when count(*)=0 then 1 else  count(*) end)*100,2) speeding_80_90,
       ROUND(nvl(sum(case  when to_number(speed) > 90 and to_number(vehicle_speed) <= 100 then  1  else  0 end),0)/(case when count(*)=0 then 1 else  count(*) end)*100,2) speeding_90_100,
       ROUND(nvl(sum(case  when to_number(speed) > 100  then  1  else  0 end),0)/(case when count(*)=0 then 1 else  count(*) end)*100,2) speeding_100_140 
   from A_B_C_data_t 
 where vehicle_speed !='FFFF'
   and vehicle_vin = '12345678'
   and vehicle_speed is not null
   and TEMINAL_TIME < add_months(to_date('2011-06', 'yyyy-mm'), 1)
   and TEMINAL_TIME >= to_date('2011-06', 'yyyy-mm')
这里没有加分区条件 partition ("SEC_DATA_20110627") 我想问一下 可不可以 分区条件 是一个月的呢 因为报表时按一个月来统计的 而分区时按天来分区的    

解决方案 »

  1.   

    能不能说的在细一些 因为这个表 我加了个全局索引对vehicle_speed字段 可惜 查询 还是 很慢 6秒到 8秒 数据量 是300W多点 再问一下 和数据库有关系么 我在另一个数据库中查询180W数据量的 才用0.6秒
      

  2.   

    就目前来说 不会修改数据库的设计 而且这个表本身就是秒数据表 虽然现在300W 那只是现在测试阶段的数据,之后 会更多的,目前这地方想做优化 让报表显示的更快一些 就是用某些工具做的 柱状图 感觉显示的慢了些, 而且目前有个疑问 就是 开发库里面 数据100W+  和 测试库里面300W+数据同样的SQL 查询的效率差很多  一个0.6秒  一个 8秒  这个 数据库本身有关系么 
      

  3.   

    其实 我主要 想问的是 这种情况 从SQL优化上 可以实现么 如果不可以实现那么 创建索引呢 是否可以解决 这个问题
      

  4.   

    麻烦各位了 还想问一下 如果 select sum(a)  ....  这个sum计算的数据量 10W的话 那么 速度 会不会很慢 优化的话 怎么优化 从哪个角度去优化