【发布时间】:2012-11-16 10:38:47
【问题描述】:
我有一个问题:
<cfquery name="getDesc" datasource="#ds#">
SELECT
desc,
SUM(charge) as cost,
COUNT(*) as cnt
FROM
product
WHERE Length(desc) > 0
</cfquery>
然后填充一个表格:
<table>
<tbody>
<tr>
<th>Description</th>
<th>Amount of Charges</th>
<th>Cost (£)</th>
</tr>
<cfoutput query="getDesc">
<tr>
<td>
#HTMLEditFormat(getDesc.desc)# <br />
</td>
<td>
#HTMLEditFormat(getDesc.cnt)# <br />
</td>
<td>
#HTMLEditFormat(getDesc.cost)# <br />
</td>
</tr>
</cfoutput>
</tbody>
</table>
我的问题是我想合并表中具有相同值的两行,并将它们的两个计数加在一起。
到目前为止我有:
<table>
<tbody>
<tr>
<th>Description</th>
<th>Amount of Charges</th>
<th>Cost (£)</th>
</tr>
<cfoutput query="getDesc">
<tr>
<cfif getDesc.desc EQ 'No Charge' OR getDesc.desc EQ 'No Charge (2)'>
<td>
No Charge & (2)
</td>
<td>
<cfset cntSum = arraySum(getDesc['cnt'])>
#cntSum#
</td>
<cfelse>
<td>
#HTMLEditFormat(getDesc.desc)# <br />
</td>
<td>
#HTMLEditFormat(getDesc.cnt)# <br />
</td>
</cfif>
<td>
#HTMLEditFormat(getDesc.cost)# <br />
</td>
</tr>
</cfoutput>
</tbody>
</table>
但这给了我两行'No Charge & (2)',计数是表中所有其余行的总和,而不仅仅是我想要的两行。
希望这是有道理的。
【问题讨论】:
标签: mysql loops coldfusion coldfusion-8 addition