Sum a field in query

BobJones

Registered User.
Local time
Today, 16:44
Joined
Jun 13, 2006
Messages
42
I have two tables, Group and Person.
A group can hold one or more persons, linked by a field called GroupID.
And a person can be a leader of a group.
I want to make a query to return the leaders of the group, which I can do, ie. where tblPerson.Leader = true, but I also want to calculate the number of persons in that group.

Any ideas or if you need more information, please let me know
Bob

Thinking about it, I suppose its more of a count function than a sum function, but I've never been the best with queries
 
Last edited:
OK well once again, I solved it by myself...

So for anyone thats interested, it involved two queries.
qryInvoice:
Code:
SELECT tblGroup.GroupID, tblPerson.FirstName+' '+tblPerson.LastName AS Name, tblPerson.Address1+', '+tblPerson.Address2 AS Address, [COLOR="Red"]qryInvoiceGroupCount.CountID AS [No in party][/COLOR],
FROM (tblGroup INNER JOIN tblPerson ON tblGroup.GroupID=tblPerson.GroupID) INNER JOIN qryInvoiceGroupCount ON tblGroup.GroupID=qryInvoiceGroupCount.GroupID
WHERE (((tblPerson.Leader)=True));

qryInvoiceGroupCount:
Code:
SELECT DISTINCT tblPerson.GroupID, Count(tblPerson.GroupID) AS CountID
FROM tblGroup INNER JOIN tblPerson ON tblGroup.GroupID=tblPerson.GroupID
WHERE (((tblPerson.GroupID)=tblGroup.GroupID))
GROUP BY tblPerson.GroupID;

Theres probably a more efficient way of doing this but as I had to figure it out myself, its the best I could come with.

Bob
 

Users who are viewing this thread

Back
Top Bottom