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%'
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 table8 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 table9 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 table10 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 table11 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 table12 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 table13 with(nolock) where (isQC is null or isQC =0 ) and inputtime like '2013%'
)
select * from t1 SQL?Server SQL
[解决办法] 建议将union改为union all.. [解决办法]
如果能走索引的话,1000万不算多。 如果不需要去重,建议把union改成union all [解决办法] 要改善效率,要从设计上着手。。这分表设计又要联合查询,其本身的问题就很多 [解决办法] 100万条数据获取处理意义不大, 看看你的业务逻辑是不是要分页哦 [解决办法]
100万条数据获取处理意义不大, 看看你的业务逻辑是不是要分页哦
是有,
那就测试你分页时候的时间,这个比较有意义 [解决办法] 那把每个表的inputtime 做索引, 同时where (isQC is null or isQC =0 ) and inputtime like '2013%' 写成where inputtime like '2013%' and (isQC is null or isQC =0 ) 试试