Reply
Find the SUM of a Column (Join)
Old 05-15-2008, 10:59 AM Find the SUM of a Column (Join)
Skilled Talker

Posts: 55
Name: Nick Martin
Hey..

I'm trying to find the sum the the 'Price' column. Can anyone give me an idea on how to do this with the following join


Code:
SELECT tblServiceLocation.Description, tblService.Description, tblVehicleService.Price,
tblVehicleService.ID, tblService.ID
FROM 
tblVehicleService, tblServiceLocation, tblService
WHERE tblVehicleService.ServiceLocationID = tblServiceLocation.ID
AND tblVehicleService.ServiceID = tblService.ID
SpudNik is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 05-15-2008, 11:00 AM Re: Find the SUM of a Column (Join)
Skilled Talker

Posts: 55
Name: Nick Martin
Thanks in Advance for the help!!

-Nick
SpudNik is offline
Reply With Quote
View Public Profile
 
Old 05-15-2008, 12:43 PM Re: Find the SUM of a Column (Join)
Learning Newbie's Avatar
Moderator

Latest Blog Post:
Dick Cheney as a Web Comic
Posts: 4,696
Name: John Alexander
You're using Access?

At the bottom of your query, add

GROUP BY
tblServiceLocation.Description, tblService.Description

Then get rid of the tbl wart from your table names.
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 05-16-2008, 04:50 AM Re: Find the SUM of a Column (Join)
Average Talker

Posts: 21
Location: London, UK
You forgot the SUM aggregate:

SELECT tblServiceLocation.Description, tblService.Description, SUM(tblVehicleService.Price),
tblVehicleService.ID, tblService.ID
FROM
tblVehicleService, tblServiceLocation, tblService
WHERE tblVehicleService.ServiceLocationID = tblServiceLocation.ID
AND tblVehicleService.ServiceID = tblService.ID
GROUP BY tblServiceLocation.Description, tblService.Description, tblVehicleService.ID, tblService.ID
vividearth is offline
Reply With Quote
View Public Profile Visit vividearth's homepage!
 
Old 05-19-2008, 11:13 AM Re: Find the SUM of a Column (Join)
Skilled Talker

Posts: 55
Name: Nick Martin
Thank you both for the replies. Lemme give this a shot.

I like "tbl" naming convention
SpudNik is offline
Reply With Quote
View Public Profile
 
Old 05-19-2008, 11:24 AM Re: Find the SUM of a Column (Join)
Skilled Talker

Posts: 55
Name: Nick Martin
So these all give the same result set; basically. The SUM column gets the sum for each particular price. What I need is the total of all the sums in the price column. Does that make sense?
SpudNik is offline
Reply With Quote
View Public Profile
 
Old 05-19-2008, 12:13 PM Re: Find the SUM of a Column (Join)
Skilled Talker

Posts: 55
Name: Nick Martin
Thanks guys. I was able to get it done with a UNION.
SpudNik is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Find the SUM of a Column (Join)
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13195 seconds with 13 queries