如果是myisam引擎的表 可以从系统表统计
select sum(TABLE_ROWS) from information_schema.tables where table_name like 'tab%';
如果是innodb 用以上方法只能得到大概的数字
select sum(TABLE_ROWS) from information_schema.tables where table_name like 'tab%';
如果是innodb 用以上方法只能得到大概的数字
另外多问一句,如果不依赖系统表,或者我的count操作,后面会带where条件时,这个能否搞定?
稍微调整下:
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;
生成需要的语句,去掉最后的UNION ALL
2. select sum(cnt) from (动态生成的) a