当前位置:Gxlcms > 数据库问题 > Mysql分表之后的聚合统计

Mysql分表之后的聚合统计

时间:2021-07-01 10:21:17 帮助过:2人阅读

对于分表数目比较少的情况,直接用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   分表   

人气教程排行