Toplam toplam sütunun doğru sayıya eşit olmasını sağlayacak şekilde, sorgumu düzeltmeye çalışıyorum. Bu satırı <cfset columnSum = ArraySum(allLocCode['locationCount'])>
'u <cfset columnSum = ArraySum(trim(allLocCode['locationCount']))>
olarak değiştirmeyi denedim ama bir hatayla. Aşağıdaki resimde olduğu gibi boş bir dizgeyi, tabloda görünmediği gibi toplam için sayılmamasını istiyorum. Bu sütunu benim toplam sütun için çekmenin başka bir yolu var mı? Lütfen daha fazla yardım gerekiyorsaCF sorgu toplam toplamı için boş karakter dizisi sonuçlarını sil
<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>
: Doğru cevap 334 yansıtmalıdır
<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>
değil 340 istendiği gibi
Bu, ilk sorgu, 'allLocCode '' nizi yalnızca TRANS_LOCATION sütununun boş veya boş olmadığı satırları döndürmek için düzenleyerek düzeltilemedi. Şu anda WHERE yan tümcesi yoktur. – TRose
Serbest puanlar eğlencelidir, ancak genellikle yalnızca gönderim sırasında güvendiğim cevapları toplardım. Yorumum mutlu bir kazaydı. Memnun kaldım! – TRose
Örneğinizdeki her şey% 100'dür, yani ortalama yüzdeyi kastediyorsunuzdur? Tüm yüzdeleri bir liste veya dizide koyarsınız, tıpkı yer sayımlarında yaptığınız gibi, sonra da ilgili sorguya ait kayıt sayısını bölersiniz. – TRose