superliming 发表于 2010-5-10 10:15:29

sql优化问题

这个语句执行要200多秒,其实只有30多条内容。请问如何优化下
select to_char(trunc(A.org_time,'iw'),'yyyy-mm-dd') as 时间,
   A.device_name as device_name,
   B.cuid as cuid ,
   B.link_id,
   B.LINK_DESCRIPTION ,
       B.left_equip_id asleft_equip ,
       B.left_port_name as left_port_name ,
       A.ifspeed /1000/1000 as ifspeed ,
       max(nvl(A.MAXIFINOCTETS_SPEED,0)) as M3,
       avg(nvl(A.AVGIFINOCTETS_SPEED,0)) as M5,
       max(nvl(A.MAXIFINOCTETS_SPEED,0)) /(A.ifspeed/1000/1000) *100 as maxinuing ,
       avg(nvl(A.AVGIFINOCTETS_SPEED,0)) /(A.ifspeed/1000/1000) *100 as avginuing
fromSA_DMP.rpt_network_interface_hour A ,
    SA_OMP.设备链路 B
where A.device_name = B.left_equip_idand
(B.cuidlike '%BC-SXNET-RT%' or B.cuidlike '%BA-IPNET-RT%') andB.cuid not like '%CE%'
and B.left_port_name = A.ifname      
and trunc(A.org_time,'iw') >= trunc(to_date('2010-04-26','yyyy-mm-dd'),'iw')
andtrunc(A.org_time,'iw') < trunc(to_date('2010-05-04','yyyy-mm-dd'),'iw')
group by to_char(trunc(A.org_time,'iw'),'yyyy-mm-dd'), B.cuid ,A.device_name ,B.left_equip_id ,B.left_port_name ,A.ifspeed ,B.link_id ,B.LINK_DESCRIPTION
order by to_char(trunc(A.org_time,'iw'),'yyyy-mm-dd'),B.LINK_DESCRIPTION asc

archonwang 发表于 2010-5-11 14:28:42

。。。
老实说,使用了group by和order by速度必然下降,你试试看不用这两个,能快多少?
页: [1]
查看完整版本: sql优化问题