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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Do Math on a Query RecordSet? 1

Status
Not open for further replies.

3dColor

Programmer
Jan 10, 2006
240
US
I have a query that returns a record set of sale prices. I want to add those sales number and the then divide it by the recordcount to get the average.

I am pretty sure I can handle the math function to divide the total by the recordcount - but how do I add up the sale prices in to a total?

Do I need to create a loop for this?
 
Code:
<cfquery>
Select Sum(YourColumnName) AS SalesTotal
From YourTableName
</cfquery>

Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
Adding to ECAR's reply,

the WHERE condition for the SUM query should be the same as that used in your other query.
 
and just to add, the SUM function should be used in the same query that is getting the data now, not a separate query just for the sum. ecar was just giving an example of the SQL function.

Kevin

Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top