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 
原文地址:https://www.cnblogs.com/yanximin/p/10985987.html