use*_*110 1 coldfusion row sum cfml
我之前问过这样的问题,但没有得到任何好的答案,可能是因为代码太长或我的问题不清楚.这个时候我会尽我所能:)到目前为止,我已经编写了代码来从表中查找行和,这很好:
<cfloop list="#product_id_list#" index="product_index">
    <cfloop list="#month_list#" index="month_index">
        <cfoutput query="GET_SALES_TOTAL">
            <cfif AY eq month_index and product_id eq product_index>
                <cfloop list="#type_index#" index="tt_index">
                    <cfset 'alan_#tt_index#_#month_index#_#product_index#' = evaluate(tt_index)>
                </cfloop>
            </cfif>
        </cfoutput>
    </cfloop>
</cfloop>
<cfset 'total_#ii_index#_#p_index#'=evaluate('total_#ii_index#_#p_index#') + #evaluate('alan_#ii_index#_#ddd_other#_#p_index#')#>
现在我想找一个列总和.列总和的代码有效,但不正确.它计算最后一个产品的总和:
<cfloop list="#product_id_list#" index="product_index">
    <cfloop list="#month_list#" index="month_index">
        <cfoutput query="GET_SALES_TOTAL">
            <cfif AY eq month_index and product_id eq product_index>
                <cfloop list="#type_index#" index="tt_index">
                    <cfset 'alan2_#tt_index#_#month_index#_#product_index#' = evaluate(tt_index)>
                </cfloop>
            </cfif>
        </cfoutput>
    </cfloop>
</cfloop>
<cfset 'total2_#ddd_other#_#p_index#'=evaluate('total2_#ddd_other#_#p_index#') + #evaluate('alan2_#ii_index#_#ddd_other#_#p_index#')#>
行和的输出:
<cfloop list="#product_id_list#" index="p_index">
    <cfloop list="#type_index#" index="kk_ind">
        <td align="center">
          <font color="##FF0000">#TLFormat(evaluate('total_#kk_ind#_#p_index#'),0)#</font>
        </td> 
    </cfloop>
</cfloop>
列总和的输出:
<cfloop list="#month_list#" index="kk">
 <td align="center">
   <cfset satis_oran= evaluate('total2_#kk#_#p_index#')>
     #evaluate(satis_oran)#
 </td>
</cfloop>
我知道我没有按产品ID循环列输出,因为一旦我循环它,它会产生很多<td>,这意味着很多不相关的数据.这可能是什么错误?
Jas*_*son 17
如果您的查询中有一列,并且您可以确保每个值都是数字,您还可以执行以下操作:
<cfset sum = arraySum(queryname['column'])>
如果它遇到任何非数字值,它将导致错误,因此您可能需要在该字段周围放置一个coalesce语句,以确保任何空值转换为零.