Mysql分表之后的聚合统计

Posted yanximin

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mysql分表之后的聚合统计相关的知识,希望对你有一定的参考价值。

对于分表数目比较少的情况,直接用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分表之后的聚合统计的主要内容,如果未能解决你的问题,请参考以下文章

mysql分库分表

mysql分库分表

如何在Kibana中过滤聚合统计值

分库分表后的分页查询

MySQL聚合函数

Mysql精华问答| 分库分表之后,ID主键及事务如何处理