Solved

SUM in one-to-many relationship

Posted on 2008-09-29
1
173 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now