【问题标题】:MySQL count across multiple tables and get single valueMySQL跨多个表计数并获得单个值
【发布时间】:2012-09-20 15:37:44
【问题描述】:

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

我需要在每个表上运行单独的选择,并以单个数量报告计数,即:

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

我的最终结果应该是 = 9

【问题讨论】:

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


    【解决方案1】:

    你已经很接近了;你可以写:

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

    【讨论】:

      【解决方案2】:
      select 
          (select count(*) from t1)
          + (select count(*) from t2)
          + (select count(*) from t3);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-05-15
        • 2020-11-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多