你这一句是不是错了,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就是你想要的结果
你可以不这么写啊。
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就是你想要的结果
Union后是索引不管用了。
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 排序去掉重复(效率低应该就出在这里了)再统计最终结果
怎样在视图上建立索引。
http://search.csdn.net/Expert/topic/630/630342.xml?temp=.973263
select * from Customer
union
select * from Customer_History
go
--
create
--unique clustered
index indexname on v_customer(视图中要加索引的列)
GO
改成:select count(1) from Customer where createtime>='2002-1-2' and createtime<='2002-12-31'
,rouqu(Silent Hill)
建立索引后 问题解决。