你这一句是不是错了,select count(*) from Customer_History where createtime>'2002-1-1' and createtime<'2003-1-1'是不是该为select count(*) from v_customer where createtime>'2002-1-1' and createtime<'2003-1-1'没有处理过这么大数据量,留个记号
你可以不这么写啊。
declare @a numeric 
declare @b numeric  
select @a=count(*) from Customer_History where createtime>'2002-1-1' and createtime<'2003-1-1'
select @b=count(*) from Customer_History where createtime>'2002-1-1' and createtime<'2003-1-1'
select @a+@b就是你想要的结果 

解决方案 »

  1.   

    用Union肯定是要慢的哈~~~何况你的数据量这么大。
      

  2.   

    不知你用Union后是不是你的哪些索引估计就不管用了。
      

  3.   

    to hmily1688(没什么好说的) 
    Union后是索引不管用了。
      

  4.   

    没办法,你这种查询应该是没有办法优化的了它的执行过程已经进行了优化,先执行:
    select * from Customer where createtime>'2002-1-1' and createtime<'2003-1-1'
    select * from Customer_History where createtime>'2002-1-1' and createtime<'2003-1-1'再将这两个结果集合并在一齐,并order by 排序去掉重复(效率低应该就出在这里了)再统计最终结果
      

  5.   

    to  netcoder(朱二) :
    怎样在视图上建立索引。
      

  6.   

    楼主见这
    http://search.csdn.net/Expert/topic/630/630342.xml?temp=.973263
      

  7.   

    create view v_customer as 
    select * from Customer 
    union 
    select * from Customer_History
    go
    --
    create 
    --unique clustered 
    index indexname on v_customer(视图中要加索引的列) 
    GO
      

  8.   

    create index indexname on v_customer(createtime) 和在表上建索引一样
      

  9.   

    select count(*) from Customer where createtime>'2002-1-1' and createtime<'2003-1-1'
    改成:select count(1) from Customer where createtime>='2002-1-2' and createtime<='2002-12-31'
      

  10.   

    谢谢 hmily1688(没什么好说的) 
    ,rouqu(Silent Hill)
    建立索引后 问题解决。