简体   繁体   中英

Sum value of all rows of a column with multiple tables

Im using this to get a total count

$exe = mysql_query('SELECT SUM(field_3) FROM t_a');
$res = mysql_fetch_row($exe);
echo 'Total Count: ' .$res[0] . ' / XX';

But I need it from multiple tables with the same structure, named t_a, t_b, all the way to t_z

You can use Union All in my sql

select sum(field_3) total
from
(
    select field_3
    from t_a
    union all
    select field_3
    from t_b
) t
group by field_3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM