2016-04-04 24 views
0

私は、ColdFusionを使用してMS SQLデータベースからクエリを実行して、ロケーション名、合計チェックリストの割合、ロケーションの合計。CFクエリPercentagesの計算と合計行の合計の追加

チェックリストの各ブランチの位置のパーセンテージを計算することに失敗しているようです。私は各支店の場所のパーセントを取得しようとしているし、すべてのブランチの合計を合計する合計の行を作成します。

これは私が持っているものですが、何らかの理由で各ブランチのパーセンテージを表示せずに合計を下に表示するのではなく、すべての場所で100%を取得し続けます。

これに関するお手伝いをさせていただきますようお願い申し上げます。 I am trying to get the percent of each branch location and then create a sum total line that will add the total of all branches together.について

<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(trans_location) 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> 
    </tbody> 
    <!--- Total of All Sum of each column ---> 
    <tr> 
     <td><strong>Total</strong></td> 
     <td></td> 
     <td></td> 
    </tr> 
</table> 

enter image description here

+0

ループ内でdbクエリを送信するのではなく、SQLでこの作業のほとんどを直接実行することから始めます。 –

答えて

1

、配列関数は、クエリの列に取り組んでいます。構文は、

columnSum = ArraySum(queryName['columnName'] 
+0

なぜ分割部が失敗しているのか、すべて100%ありますか? –

+0

私はこのクエリを必要としないように感じます。 '

+0

ちょっとちょっとこのようにしようとしましたが、 '値がすべて加算されていない –

関連する問題