troubleshooting Question

SQL SUM Across Tables

Avatar of neptune2528
neptune2528 asked on
Microsoft AccessMicrosoft SQL Server
8 Comments1 Solution757 ViewsLast Modified:
OK, I have to write a query to sum the values returned from multiple tables.  The details are as follows:

TABLE A contains the field I would like to sum, lets call it NUMBER in TABLE A.  TABLE B contains a set of classifications for records in TABLE A.  The field in TABLE B is CLASSIFICATION and can have the following values: CLASS 1, CLASS 2 and CLASS 3.  A single record in TABLE A can, and will, have many classifications in TABLE B.  For example, a single record in TABLE A can be CLASS 1, CLASS 2 and CLASS 3 and any combination thereof.  

I want to be able to sum the NUMBER field from TABLE A across records that have related records in TABLE B for CLASS 1, CLASS 2 and CLASS 3.  Please note in the example, the record in TABLE A must have all three classes to be valid for the summation.  If it only has CLASS 1 and CLASS 2, then it should not be included.

Assume a simplified data model as follows:

TABLE A
 - ID (unique identifier)
 - NUMBER

TABLE B
 - ID (relationship to TABLE A)
 - Classification
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros