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

Add up data

Status
Not open for further replies.

stevenfilip

Programmer
Joined
Feb 5, 2003
Messages
5
Location
NL
Hi All,

For example I have two colums

country | amount
------------------
usa | 10
uk | 21
usa | 19
usa | 2
uk | 12
usa | 11

Now I would like to output the total of a country
so that I would get :

usa 42
uk 33

How would I do something like that in Coldfusion?

Thanks!
 
if your two columns are in a database table, use sql

select country, sum(amount)
from yourtable
group by country

rudy
 
Hi,

Thanks!

Call me stupid, but how would I output this data?
 
you would output it with a CFOUTPUT tag

oh, you should also give a column alias to the aggregate

<CFQUERY NAME=&quot;foo&quot;>
select country, sum(amount) as totalamt
from yourtable
group by country
</CFQUERY>

<CFOUTPUT QUERY=&quot;foo&quot;>
#country# #totalamt#
</CFOUTPUT>

rudy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top