User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ColdFusion section within the Web Development category of DaniWeb, a massive community of 391,553 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,585 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ColdFusion advertiser:
Views: 2161 | Replies: 2
Reply
Join Date: Dec 2006
Posts: 5
Reputation: shaggysc96 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
shaggysc96 shaggysc96 is offline Offline
Newbie Poster

Question help! need to accumulate total

  #1  
Dec 19th, 2006
:rolleyes: I am trying to develope a simple application that will record a teams miles per week and total miles I have the code working to accumulate the total, but the problem is how to I get it to accumulate just for the one team and not for all? How do I get it to accumulate for just one team Name? Code is as follows:

Code:
<CFQUERY NAME="Mileage" DATASOURCE="#dsn#">SELECT weeklyMileage, totalMileageFROM mileage</CFQUERY>cfset totalMileage= 0> <cfloop query="Mileage"><cfset totalMileage =totalMileage + Mileage.weeklyMileage></cfloop> <cfquery datasource="#dsn#" dbtype="ODBC"> Insert Into mileage (dateupdated,teamName,teamLeader,email,weeklyMileage,mileageWeekNumber,comments,totalMileage) Values ('#Trim(thetime)#','#Trim(teamName)#','#Trim(teamLeader)#','#Trim(email)#','#Trim(weeklyMileage)#','#Trim(mileageWeekNumber)#','#Trim(comments)#','#Trim(totalMileage)#')</cfquery>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2006
Location: Near Chicago
Posts: 79
Reputation: nikkiH is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 4
nikkiH's Avatar
nikkiH nikkiH is offline Offline
Junior Poster in Training

Re: help! need to accumulate total

  #2  
Dec 29th, 2006
Missing a where?

SELECT weeklyMileage, totalMileageFROM mileage WHERE teamName=#teamName#
Google is your friend. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit http://www.kaelisspace.com/
Reply With Quote  
Join Date: Jan 2007
Location: Austin, TX
Posts: 30
Reputation: Memento is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Memento Memento is offline Offline
Light Poster

Re: help! need to accumulate total

  #3  
Jan 14th, 2007
Originally Posted by nikkiH View Post
Missing a where?

SELECT weeklyMileage, totalMileageFROM mileage WHERE teamName=#teamName#


You also may want to look into using the GROUP by clause. For example, if your data is as follows:

team, week_nbr, week_miles
A,1,4
A,2,4
A,3,6
B,2,5
C,1,3
C,2,6

You could write a query like:

SELECT team, SUM(week_miles) as total_miles
FROM your_tbl_name
GROUP BY team

Which would return
team, total_miles
A, 14
B, 5
C, 9


Like nikkiH said, you can also use this with a where clause.

Good luck,
Dan
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ColdFusion Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ColdFusion Forum

All times are GMT -4. The time now is 9:25 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC