MySQL在多个表中计数并获得单个值

时间:2012-09-20 15:37:45

标签: mysql select count inner-join union-all

想象:     t1 = 1     t2 = 3     t3 = 5

我需要在每张桌子上运行单独选择,并以一个数量报告计数,即:

 select * 
   from (select count(*) from t1)
          + (select count(*) from t2)
          + (select count(*) from t3);

我的最终结果应该是= 9

2 个答案:

答案 0 :(得分:3)

你很亲密;你可以写:

 select (select count(*) from t1)
        + (select count(*) from t2)
        + (select count(*) from t3)
 ;

答案 1 :(得分:1)

select 
    (select count(*) from t1)
    + (select count(*) from t2)
    + (select count(*) from t3);