本帖最后由 guonaiqi 于 2009-10-19 17:32:18 编辑

解决方案 »

  1.   

    select count(*) from (
    select id from a
    union all
    select id from b
    union all
    select id from c
    union all
    select id from d) aa
      

  2.   

    select sum(t1.num) as '总记录数' from ( 
    select count(*) as num from a 
    union all 
    select count(*) from b 
    union all 
    select count(*) from c 
    union all 
    select count(*) from d) t1 
      

  3.   

    select (select count(*) as a from 表A)+
    (select count(*) as a from 表B)+
    (select count(*) as a from 表C)+
    (select count(*) as a from 表D);
      

  4.   

    select count(1)
    from
    (select 1 from a
     union all
     select 1 from b
     union all
     select 1 from c
     union all
     select 1 from d
    ) as t
      

  5.   

    mysql> select * from aa;
    +------+---------+--------+
    | id   | content | parent |
    +------+---------+--------+
    |    1 | AAAAAA  |   NULL |
    |    2 | BBBBBB  |   NULL |
    |    3 | cccccc  |      2 |
    +------+---------+--------+
    3 rows in set (0.00 sec)mysql> select * from b;
    +-------+------+
    | test  | full |
    +-------+------+
    | test1 | 50   |
    | test2 | 70   |
    | test3 | 100  |
    +-------+------+
    3 rows in set (0.00 sec)mysql> set @count=0;
    Query OK, 0 rows affected (0.02 sec)mysql> select count(*) into @count from aa;
    Query OK, 1 row affected (0.00 sec)mysql> select @count+count(*) from b;
    +-----------------+
    | @count+count(*) |
    +-----------------+
    |               6 |
    +-----------------+
    1 row in set (0.00 sec)
      

  6.   

    如果表小的话,可以用union 联合起来弄。
    如果表大了(单表超过100万),别这么干,那你服务器真要玩完了。这个时候你不如就先select,把结果插到一个临时表里,再sun一下就可以了。或者用存储过程写下就可以了