2012-12-13 237 views

回答

0

試試這個

SELECT SUM(number) AS total FROM table; 
0

您可以查詢該表是這樣的:

select sum(number) from table; 

,並有mysql算一下。

1

嘗試做的Thuis

select number ,sum(number) as total from table; 

然後做

$row['total'] // and it gives u the total sum 
1

在PHP層:

$cnt = 0; 
while($row = mysql_fetch_assoc($result)) { 
    $cnt += $row['yourfield']; 
} 

在MySQL的LEVE:

SELECT SUM(yourfield) 
FROM yourtable 
GROUP BY yourfield