码迷,mamicode.com
首页 > 数据库 > 详细

Mysql分表之后的聚合统计

时间:2019-06-06 17:22:31      阅读:743      评论:0      收藏:0      [点我收藏+]

标签:sql   from   group   聚合   情况   mys   sum   sel   分表   

对于分表数目比较少的情况,直接用union all 就行

select ring_token , sum(a.sum_partition) as total from (
    select ring_token, count(1) as sum_partition from  table_0 group by ring_token
    union all
    select ring_token, count(1) as sum_partition from  table_1 group by ring_token
    union all
    select ring_token, count(1) as sum_partition from  table_2 group by ring_token
    union all
    select ring_token, count(1) as sum_partition from  table_3 group by ring_token
    union all
    select ring_token, count(1) as sum_partition from  table_4 group by ring_token
    union all
    select ring_token, count(1) as sum_partition from  table_5 group by ring_token
    union all
    select ring_token, count(1) as sum_partition from  table_6 group by ring_token
    union all
    select ring_token, count(1) as sum_partition from  table_7 group by ring_token
) a 

Mysql分表之后的聚合统计

标签:sql   from   group   聚合   情况   mys   sum   sel   分表   

原文地址:https://www.cnblogs.com/yanximin/p/10985987.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!