After the polymerization statistical part table Mysql

For the relatively small number of part tables, the union all directly on the line

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 

Guess you like

Origin www.cnblogs.com/yanximin/p/10985987.html