acc_yqdz表有15万条记录,aaalszb有3万条记录,
但是这个SQL执行完后,用了1个多小时还没有完,
请高手帮忙修改优化一下,多谢!!
update acc_yqdz t4
set t4.a8fse=nvl(t4.a8fse,0)+(
select fse from
(
select
a5sh,a5zh,a8jd,a5dwm,a5gskm,a5bz,a5sh||a5zh||a8jd as yy,sum(a5ye) as ye
from whrept.acc_yqdz
where (substr(a5gskm,1,3) in ('202','205','251')
or substr(a5gskm,1,3) in ('201','221'))
and a5bzh='01'
group by a5sh,a5zh,a8jd,a5dwm,a5gskm,a5bz
) t1,
(
select a8date,a8sh,a8zh,a8jd,a8sh||a8zh||a8jd as dd,sum(a8fse) as fse from aaalszb
where (substr(a8kmh,1,3) in ('202','205','251')
or substr(a8kmh,1,3) in ('201','221') )
and a8bzh='01'
group by a8date,a8sh,a8zh,a8jd
) t2
where t1.yy=t2.dd
and substr(t1.a5bz,6,1)<>;'2'
and t4.a5sh=t1.a5sh and t4.a5zh=t1.a5zh and t4.a8jd=substr(t1.yy,19,1)); |