PHP:值的总和列表

时间:2010-07-17 03:52:24

标签: php list sum

我有一个像这样的信息列表......

No. Customer Bank_Name Amount
-----------------------------
1.  AAA      Bank A    100 
2.  BBB      Bank B    200 
3.  CCC      Bank A    500 
4.  DDD      Bank C    150 
-----------------------------
Total                  950 

如何使用PHP为每个银行汇总此信息,因此结果如下所示......

No. Bank_Name Total
-------------------
1.  Bank A    600 
2.  Bank B    200 
3.  Bank C    150 
-------------------

1 个答案:

答案 0 :(得分:3)

如果它在数据库中......类似于:

SELECT bank, SUM(amount) as `sum`
FROM customers
GROUP BY bank
ORDER BY bank