![](/img/trans.png)
[英]Get the sum of a column value for all rows with same value in different column
[英]Sum value of all rows of a column with multiple tables
我用它來得到總數
$exe = mysql_query('SELECT SUM(field_3) FROM t_a');
$res = mysql_fetch_row($exe);
echo 'Total Count: ' .$res[0] . ' / XX';
但我需要從具有相同結構的多個表中獲取它,名為t_a,t_b,一直到t_z
你可以在我的sql中使用Union All
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.