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

一条sql语句,执行太慢了,请教下怎么优化
一条sql语句,执行太慢了,请教下怎么优化。主要是里面有31条子查询,子查询里面又有联合查询,所以才比较慢。
请教一下改怎么优化啊?
语句如下,由于csdn限制发帖字数,我只写了到as   d7,其实后面还有一直要到as   d31,所以不慢才怪呢,但是不知道该怎么优化一下呢
select   HRM_KQMONTH.*,((select   case   when   ctype= '04 '   then   (select   symbol   from   hrm_setdata   where   TID   =   'QJ '   and   did=hrm_kqDay.qtype)   else   (select   symbol   from   hrm_setdata   where   TID   =   'KQ '   and   did=hrm_kqDay.ctype)   end   from   hrm_kqDay   where   KSTATUS= 'T '   and   to_char(KDate, 'yyyy ')= '2007 '   and   to_char(KDate, 'mm ')= '08 '   and   to_char(kDate, 'dd ')= '01 '   and   PersonID=HRM_KQMONTH.personid))   as   d1,((select   case   when   ctype= '04 '   then   (select   symbol   from   hrm_setdata   where   TID   =   'QJ '   and   did=hrm_kqDay.qtype)   else   (select   symbol   from   hrm_setdata   where   TID   =   'KQ '   and   did=hrm_kqDay.ctype)   end   from   hrm_kqDay   where   KSTATUS= 'T '   and   to_char(KDate, 'yyyy ')= '2007 '   and   to_char(KDate, 'mm ')= '08 '   and   to_char(kDate, 'dd ')= '02 '   and   PersonID=HRM_KQMONTH.personid))   as   d2,((select   case   when   ctype= '04 '   then   (select   symbol   from   hrm_setdata   where   TID   =   'QJ '   and   did=hrm_kqDay.qtype)   else   (select   symbol   from   hrm_setdata   where   TID   =   'KQ '   and   did=hrm_kqDay.ctype)   end   from   hrm_kqDay   where   KSTATUS= 'T '   and   to_char(KDate, 'yyyy ')= '2007 '   and   to_char(KDate, 'mm ')= '08 '   and   to_char(kDate, 'dd ')= '03 '   and   PersonID=HRM_KQMONTH.personid))   as   d3,((select   case   when   ctype= '04 '   then   (select   symbol   from   hrm_setdata   where   TID   =   'QJ '   and   did=hrm_kqDay.qtype)   else   (select   symbol   from   hrm_setdata   where   TID   =   'KQ '   and   did=hrm_kqDay.ctype)   end   from   hrm_kqDay   where   KSTATUS= 'T '   and   to_char(KDate, 'yyyy ')= '2007 '   and   to_char(KDate, 'mm ')= '08 '   and   to_char(kDate, 'dd ')= '04 '   and   PersonID=HRM_KQMONTH.personid))   as   d4,((select   case   when   ctype= '04 '   then   (select   symbol   from   hrm_setdata   where   TID   =   'QJ '   and   did=hrm_kqDay.qtype)   else   (select   symbol   from   hrm_setdata   where   TID   =   'KQ '   and   did=hrm_kqDay.ctype)   end   from   hrm_kqDay   where   KSTATUS= 'T '   and   to_char(KDate, 'yyyy ')= '2007 '   and   to_char(KDate, 'mm ')= '08 '   and   to_char(kDate, 'dd ')= '05 '   and   PersonID=HRM_KQMONTH.personid))   as   d5,((select   case   when   ctype= '04 '   then   (selec