select count(*)
from
(
select * from hs2005.KeepedVoucher
union all
select * from hs2006.KeepedVoucher
union all
select * from hs2007.KeepedVoucher
union all
select * from hs2008.KeepedVoucher
union all
select * from hs2009.KeepedVoucher
union all
select * from kjhssj.KeepedVoucher ) t
这样写哪里有错额,如果一张一张统计的话比较麻烦,因为表很多
我是需要把重复的数据也算进去的,可能是语法有问题吧
select count(*)
from
(
select * from hs2005..KeepedVoucher
union all
select * from hs2006..KeepedVoucher
union all
select * from hs2007..KeepedVoucher
union all
select * from hs2008..KeepedVoucher
union all
select * from hs2009..KeepedVoucher
union all
select * from kjhssj..KeepedVoucher ) t
from
(
select count(0) ct from hs2005.KeepedVoucher
union all
select count(0) ct from hs2006.KeepedVoucher
union all
select count(0) ct from hs2007.KeepedVoucher
union all
select count(0) ct from hs2008.KeepedVoucher
union all
select count(0) ct from hs2009.KeepedVoucher
union all
select count(0) ct from kjhssj.KeepedVoucher ) t
COUNT(0)与COUNT(*)/COUNT(1)效果是一样的!,没有什么特殊的意思,据说,COUNT(1)效率高点
select (select count(*) from hs2005.KeepedVoucher )+
(select count(*) from hs2006.KeepedVoucher )+
(select count(*) from hs2007.KeepedVoucher )+
(select count(*) from hs2008.KeepedVoucher )+
(select count(*) from hs2009.KeepedVoucher )+
(select count(*) from kjhssj.KeepedVoucher )
select count(*) from hs2005.KeepedVoucher
执行上面两句有问题吗?有问题的化就是这个表名不对了 hs2005.KeepedVoucher
要改为hs2005..KeepedVoucher或hs2005.dbo.KeepedVoucher
select sum(t.c)
from
(
select count(*) c from dbo.xt_tbno
union all
select count(*) c from dbo.xt_user_resource
union all
select count(*) c from dbo.xt_role_resource
union all
select count(*) c from dbo.xt_subsystem
) t
union all效率低 慎用select (select count(*) from hs2005.KeepedVoucher )+
(select count(*) from hs2006.KeepedVoucher )+
(select count(*) from hs2007.KeepedVoucher )+
(select count(*) from hs2008.KeepedVoucher )+
(select count(*) from hs2009.KeepedVoucher )+
(select count(*) from kjhssj.KeepedVoucher )