Query Assistance - Calculating percentage
Greetings,
I may just be looking at this for way to long and not seeing the proper coding/syntax
required to accomplish what it is I am trying.
I have one query to figure out an overall count for each organization in a database. I
then have a second query to figure out the success rate count to compare to the
overall count per organization. I am running the second query inside the <cfoutput>
of the first query to achieve the desired count/display intended.
The overall and the success counts are displaying as I intend them to. However, I
am unable to get the percentage part to work. Perhaps someone can look at my
code and layout to see where it is I am failing. I have provided the desired look and
my code below for review.
I am certainly open to suggestions on how to do it differently / better, should someone
have an insight on how to accomplish my desired outcome.
CF = CF8
DB = MySQL
Thanks in advance
Leonard B
===== Desired Look =====
| Total Attempts | First Attempts | Percent | Organization Name |
|---|---|---|---|
| 20 | 18 | ?? | Org. Name |
| 40 | 33 | ?? | Org. Name |
| 51 | 44 | ?? | Org. Name |
===== Code Below =====
<cfquery name="rs_attempts" datasource="DSN">
SELECT
Count(airway_management.agency_cert_number) AS agency_count,
airway_management.agency_cert_number,
airway_management.year_of_call,
airway_management.et_attempts,
airway_management.et_attempts_successful,
airway_management.dept_org
FROM
airway_management
WHERE
airway_management.year_of_call = <cfqueryparam cfsqltype="cf_sql_integer" value="2009">
GROUP BY
airway_management.dept_org
</cfquery>
<table width="0" border="1" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td><div style="font-family: Arial; font-size: 13px">Total Attempts</div></td>
<td><div style="font-family: Arial; font-size: 13px">First Attempts</div></td>
<td><div style="font-family: Arial; font-size: 13px">Percent</div></td>
<td><div style="font-family: Arial; font-size: 13px">Organization Name</div></td>
</tr>
<cfoutput query="rs_attempts">
<tr>
<td><div style="font-family: Arial; font-size: 13px">#agency_count#</div></td>
<cfquery name="rs_1_attempts" datasource="DSN">
SELECT
agency_cert_number,
dept_org,
year_of_call,
et_attempts,
et_attempts_successful
FROM
airway_management
WHERE
year_of_call = <cfqueryparam cfsqltype="cf_sql_integer" value="2009"> AND
agency_cert_number = <cfqueryparam cfsqltype="cf_sql_varchar" value="#rs_attempts.agency_cert_number#"> AND
et_attempts = <cfqueryparam cfsqltype="cf_sql_integer" value="1"> AND
et_attempts_successful = <cfqueryparam cfsqltype="cf_sql_varchar" value="Yes">
</cfquery>
<cfset percent = ((#rs_attempts.recordcount# - #rs_1_attempts.recordcount#)*100)>
<td><div style="font-family: Arial; font-size: 13px">#rs_1_attempts.recordcount#</div></td>
<td><div style="font-family: Arial; font-size: 13px">#NumberFormat(percent,999.00)#</div></td>
<td><div style="font-family: Arial; font-size: 13px">#dept_org#</div></td>
</tr>
</cfoutput>
</tbody>
</table>