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
这样写哪里有错额,如果一张一张统计的话比较麻烦,因为表很多
我是需要把重复的数据也算进去的,可能是语法有问题吧

解决方案 »

  1.   


    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
      

  2.   

    select sum(ct) 
    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
      

  3.   

    count(0)的话是代表什么意思?
      

  4.   


    COUNT(0)与COUNT(*)/COUNT(1)效果是一样的!,没有什么特殊的意思,据说,COUNT(1)效率高点
      

  5.   


    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 )
      

  6.   

    select * from hs2005.KeepedVoucher
    select count(*) from hs2005.KeepedVoucher
    执行上面两句有问题吗?有问题的化就是这个表名不对了 hs2005.KeepedVoucher
    要改为hs2005..KeepedVoucher或hs2005.dbo.KeepedVoucher
      

  7.   

    你可以这样做啊,先把这些表的数据的条数列出来,然后在对这些表的数据进行求和就好啦。
    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
      

  8.   

    只要表的名字没错 不管字段一致不一致 都可以这么算 
    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 )
      

  9.   

    SELECT COUNT(*) FROM hs2005.KeepedVoucher,hs2006.KeepedVoucher,……