如果是myisam引擎的表 可以从系统表统计
select sum(TABLE_ROWS) from information_schema.tables where table_name like 'tab%';
如果是innodb 用以上方法只能得到大概的数字

解决方案 »

  1.   

    顶,这个方案可行。
    另外多问一句,如果不依赖系统表,或者我的count操作,后面会带where条件时,这个能否搞定?
      

  2.   

    select sum(cnt) from (select count(1) as cnt from table 1 union select ...) as all;
      

  3.   

    给力!
    稍微调整下:
    select sum(cnt) from ((select count(1) as cnt from tab_0 where colum1 = '1' ) union (select count(1) as cnt from tab_1 where colum1 = '1' )) as tab_all;
      

  4.   

    没好办法,只能多个 select count(*) from t1 union select count(*) form t2 , 然后再sum 起来。
      

  5.   

    1.select concat('select count(*) cnt',table_name,' union all') from tables where tables_schema='db'
    生成需要的语句,去掉最后的UNION ALL
    2. select sum(cnt) from (动态生成的) a
      

  6.   

    如果表名就是tab1,tab2...tab1000可以用存储去做
      

  7.   

    这种操作建议不要在需要时实时查询。这种操作除非表上无删除,否则不建议使用myisam。union要慎用,小心死锁。复杂的语句有时并不一定好。