CF查询删除总和的空字符串结果

CF query remove empty string results for total sum

我正在尝试修复我的查询,以便我的总和列将等于正确的数字。我尝试将此行 <cfset columnSum = ArraySum(allLocCode['locationCount'])> 更改为 <cfset columnSum = ArraySum(trim(allLocCode['locationCount']))> 但它通过错误。我希望下图中的空字符串不计入总数,就像它没有显示在 table 中一样。对于我的总专栏,还有其他方法可以完成这个 trim 吗?

<cfset result = {} /> 
<cftry> 
    <cfquery datasource="#application.dsn#" name="GetLocationInfo">
        SELECT *
        FROM cl_checklists
    </cfquery>

    <cfcatch type="any"> 
        <cfset result.error = CFCATCH.message > 
        <cfset result.detail = CFCATCH.detail > 
    </cfcatch> 
</cftry> 

<table border="1" id="Checklist_Stats">
    <thead>
        <th><strong>Location</strong></th>
        <th><strong>Percent of Total Checklists</strong></th>
        <th><strong>Location Total</strong></th> 
    </thead>
    <tbody>
    <cfquery name="allLocCode" dbtype="query">
        SELECT DISTINCT trans_location, COUNT(*) AS locationCount FROM GetLocationInfo GROUP BY trans_location ORDER BY trans_location 
    </cfquery>
     <cfloop query="allLocCode">
      <cfset thisLocationName = trim(allLocCode.trans_location) />

      <cfquery name="allLocCodeForLocationQry" dbtype="query">
          SELECT trans_location,count(*) AS locCntr FROM GetLocationInfo WHERE trans_location='#thisLocationName#' GROUP BY trans_location ORDER BY trans_location
      </cfquery>
      <cfoutput query="allLocCodeForLocationQry">
      <tr>
        <td><strong>#thisLocationName#</strong></td>
        <td>#NumberFormat((allLocCodeForLocationQry.locCntr/allLocCode.locationCount) * 100, '9.99')#%</td>
        <td>#allLocCodeForLocationQry.locCntr#</td>
      </tr>
     </cfoutput>
     </cfloop>
        <cfset columnSum = ArraySum(allLocCode['locationCount'])>
     <tr>
      <td><strong>Total</strong></td>
      <td></td>
      <td><cfoutput>#columnSum#</cfoutput></td>
      <cfdump var="#allLocCode#">
      <cfdump var="#allLocCodeForLocationQry#">
      <cfdump var="#thisLocationName#">
    </tr>
    </tbody>
    <!--- Total of All Sum of each column --->
</table>

正确答案应该是 334 而不是 340

根据要求,这里有一个答案,相关代码已隔离:

<cfquery name="allLocCode" dbtype="query"> 
SELECT DISTINCT trans_location, COUNT(*) AS locationCount 
FROM GetLocationInfo 
WHERE trans_location is not null 
GROUP BY trans_location 
ORDER BY trans_location 
</cfquery>

如果您在百分比方面需要更多帮助,我建议您开始新的 post。我从你的历史记录中看到你已经有几个线程与此功能相关,随着它变得越来越复杂,它将有助于分离所有内容。