日期:2014-05-17  浏览次数:20900 次

如何优化此sql语句
--几张表的数量如下:
--代码表:63条
select count(*) from etranscodeinfo; 

--机构表:4887条
select count(*) from bankdept;

--账号表:75712 条
select count(*) from eaccount;

--客户表:67363 条
select count(*) from ebankcif;

--交易表:7280737 条
select count(*) from ejnl;


select  t2.deptseq,count(*) as accamount from 
    (
          select  acseq,ea.deptseq from eaccount ea, 
     (
select t1.cifseq from ebankcif t1 
where t1.edition='1' and not exists(select 1 from ebankcif  where t1.cifseq=cifseq and opendate>t1.opendate) 
                             ) eb    
             where   ea.cifseq=eb.cifseq 
                                     and ea.authflag !=1  and 
          ( 
                         (ea.acstate='0' and ea.opendate <to_date(#nextEndDate#,'YYYY-MM-DD') )
                       or 
                       (ea.acstate='1' and ea.closedate>=to_date(#startDate#,'YYYY-MM-DD') and ea.closedate < to_date(#nextEndDate#,'YYYY-MM-DD'))
                        )
                    and ea.deptseq like #likeDeptSeq#||'%' 
    )  t2
    where  not exists 
    (
         select  1  from ejnl ej,etranscodeinfo et