Solved

SUM in one-to-many relationship

Posted on 2008-09-29
1
179 Views
Last Modified: 2011-09-20
Say I have two tables:

tblCustomer and tblPurchases
a single customer can purchase many items from the store.
If I do a regular query, the customer's name is repeated for each purchase made.

Instead I would like a TOTAL of all their purchases (Quantity) for each customer.

So a list of all the customers, and the total amount each customer has purchased.
0
Comment
Question by:NO_CARRIER
1 Comment
 
LVL 43

Accepted Solution

by:
TimCottee earned 75 total points
ID: 22595916
Hello NO_CARRIER,

Select tblCustomer.NameColumn, Sum(tblPurchases.ValueCOlumn) From tblCustomer Inner Join tblPurchases On tblCustomer.KeyColumn = tblPurchases.KeyColumn

You will need to specify the correct column names of course.

Regards,

TimCottee
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Optimize the query 5 42
Select values in a row based on values in another row in sql 4 26
SQL Syntax 14 34
Where on a calculated field 1 19
If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question