Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query help to sum field values by group 1

Status
Not open for further replies.

barkerj

Programmer
Nov 4, 2002
14
AU
Hi,

I have two tables as below.

TableA:
ID (Primary Key)
Location
Date

TableB:
ID (Primary Key)
Qty

What I am trying to do is to return a result set with the first column displaying all locations with a particular date value with the second column displaying the sum of all TableB's Qty values for that location and date.

Thus, for each line of the resultset, if there are 2 records in TableA for a particular location and date. I want to go to TableB and sum the Qty values for the corresponding IDs in that table.

Is it possible to do this using one SQL statement?
 
Something like this ?
SELECT A.Location, A.Date, Sum(B.Qty) AS TotalQty
FROM TableA A INNER JOIN TableB B ON A.ID = B.ID
GROUP BY A.Location, A.Date

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top