Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using ArraySum on a Query Column

Status
Not open for further replies.

sevex

Programmer
Sep 18, 2001
74
CA
I'm trying to use arraysum with a query column to get the sum of all the values, but it just sees the first value, instead of an array. Is there some special way to do this?

My code:
<cfquery name=&quot;get_results1&quot; datasource=&quot;xxx&quot;>
SELECT DISTINCT(q1), COUNT(q1) AS q_count FROM survey GROUP BY q1
</cfquery>

(This returns all unique records, and how many of each there are, I want a total so I can find %)

<cfset total = #ArraySum(get_results1.q_count)#>

(This is giving me an error, saying the parameter is &quot;1&quot; and not an array)

Thanks in advance for any help!
 
try using SUM aggregate function:

SELECT DISTINCT(q1), SUM(q1) AS q_count FROM ... Sylvano
dsylvano@hotmail.com
 
You can use ArraySum() although the SQL method will likely be faster.

#ArraySum(get_results1['q_count'])#
 
Thanks CFHUb, that worked great.

Thanks WWebSpider as well, although I couldn't use that method, because I needed individual counts for each distinct, as well as a total.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top