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
ASKER CERTIFIED SOLUTION
nigelrivett

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 8 Comments.
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>

Mike

Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 8 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004