问题描述
这里是场景。
我正在成功地选择并显示每个数据库条目作为html中的一行表。
I am successfully selecting and displaying each database entry as a row in a html table.
问题是报表必须具有的总字段。每个成员根据他们使用什么服务支付不同的金额,因此我必须单独添加每个字段中的值以确保正确的结果。
The problem is the total fields the report must have. Each member pays different amounts based on what services they use, so I must add the values in each field individually to ensure proper result.
问题是,如何去将行/字段添加到一起?
Question is, how do I go about adding the rows/field together?
编辑:
我添加付费和捐款付费字段。它们在mysql数据库中是分类和整数。
To clarify. I am adding dues paid and donations paid fields. They are classified and integer in mysql database.
例如,假设我的查询返回3个结果。我希望添加所有3个结果的付费,并显示为total_dues_paid。同样的想法捐赠。
Example, let's say that my query returns 3 results. I wish to add the dues paid for all 3 results and display it as total_dues_paid. Same idea for donations.
对于任何给定数量的结果,这必须是动态的,因为这个月份会发生变化,而且我们在几个月内看到了几百个结果。
This must be dynamic for any given number of results, as this changes month to month and we have seen several hundred results in some months.
感谢
推荐答案
添加字段(列):
SELECT col1, col2, col3, (col1+col2+col3) AS Total FROM table;
要将行添加到一起,请使用 SUM()
aggregate:
To add rows together, use the SUM()
aggregate:
SELECT
userid,
SUM(col1) AS col1_total,
SUM(col2) AS col2_total
FROM table
GROUP BY userid
这篇关于php / mysql将行加在一起得到总计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!