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

sqlserver 效率效率, 请指导
其中有部分的表的数据到了100多万 600多万的,请问该sql语句还有没有可以优化的地方,请高手帮忙

with t1 as(
select id,agent_id,group_id,inputtime,status_flag,r_status,stressflag,callid,stre_reason1,isQC,stre_reason2,stre_reason3,stre_reason4,stre_reason5,stre_reason6,stre_reason7,stre_reason8,stre_reason9,cust_id,calltime from table1 with(nolock) where (isQC is null or isQC =0 )  and inputtime like '2013%'
      union select id,agent_id,group_id,inputtime,status_flag,r_status,stressflag,callid,stre_reason1,isQC,stre_reason2,stre_reason3,stre_reason4,stre_reason5,stre_reason6,stre_reason7,stre_reason8,stre_reason9,cust_id,calltime from table2 with(nolock) where (isQC is null or isQC =0 )   and inputtime like '2013%'
      union select id,agent_id,group_id,inputtime,status_flag,r_status,stressflag,callid,stre_reason1,isQC,stre_reason2,stre_reason3,stre_reason4,stre_reason5,stre_reason6,stre_reason7,stre_reason8,stre_reason9,cust_id,calltime from table3 with(nolock) where (isQC is null or isQC =0 )   and inputtime like '2013%'
      union select id,agent_id,group_id,inputtime,status_flag,r_status,stressflag,callid,stre_reason1,isQC,stre_reason2,stre_reason3,stre_reason4,stre_reason5,stre_reason6,stre_reason7,stre_reason8,stre_reason9,cust_id,calltime from table4  with(nolock) where (isQC is null or isQC =0 )   and inputtime like '2013%'
      union select id,agent_id,group_id,inputtime,status_flag,r_status,stressflag,callid,stre_reason1,isQC,stre_reason2,stre_reason3,stre_reason4,stre_reason5,stre_reason6,stre_reason7,stre_reason8,stre_reason9,cust_id,calltime from table5 with(nolock) where (isQC is null or isQC =0 )   and inputtime like '2013%'
      union select id,agent_id,group_id,inputtime,status_flag,r_status,stressflag,callid,stre_reason1,isQC,stre_reason2,stre_reason3,stre_reason4,stre_reason5,stre_reason6,stre_reason7,stre_reason8,stre_reason9,cust_id,calltime from table6 with(nolock) where (isQC is null or isQC =0 )   and inputtime like '2013%'
      union select id,agent_id,group_id,inputtime,status_flag,r_status,stressflag,callid,stre_reason1,isQC,stre_reason2,stre_reason3,stre_reason4,stre_reason5,stre_reason6,stre_reason7,stre_reason8,stre_reason9,cust_id,calltime from table7 with(nolock) where (isQC is null or isQC =0 )   and inputtime like '2013%'