MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 9th, 2012, 08:38 PM
jocasio jocasio is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 2 jocasio User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 27 sec
Reputation Power: 0
Summing values in coumn 1 based on vals in another column

Hello all:

I have a table with the following data:

Code:
id	name    amount	refid 
1     	John    100.00  1 
2     	John    50.00   1 
3     	James  	100.00  3 
4     	James  	25.00   3 
5     	James  	75.00   3 
6     	George 	25.00   6 
7     	Karl	25.00 	7 
8 	Karl 	100.00 	7 

What I am trying to do is sum amount based on the refid. Id is a unique value in the db (not the primary key), and refid is what ties all of the like records (based on name) together.

I would like my results to look like the following:

Code:
Name 	Sum 
John 	150.00 
James 	200.00 
George 	25.00 
Karl 	125.00 

I'm pretty sure I have to do a subquery of some sort, but I can't get it down.

Any help is greatly appreciated

Juan

Reply With Quote
  #2  
Old July 9th, 2012, 10:16 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 43rd Plane (26000 - 26499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,443 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 14 h 22 m 31 sec
Reputation Power: 4141
Code:
SELECT name
     , SUM(amount) AS `sum`
  FROM daTable
GROUP
    BY name
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old July 10th, 2012, 06:48 AM
jocasio jocasio is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 2 jocasio User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 27 sec
Reputation Power: 0
Thanks!

I can't believe how simple that was ;-/

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Summing values in coumn 1 based on vals in another column

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap