How to get sums of groups of items in a table?

brgdotnet used Ask the Experts™
How do I get a count on the sum of the number of different GroupId's in the table below. The table is just an example.
So for the sample table below the query would produce values of 3,2,1
Because there a 3 records with GroupID of 1, two with GroupId of 2, and 1 for GroupID of 3
Table Name is "Teams"
GroupID        Name
1                     James
1                     Terry
1                     Monica
2                     Marcia
2                     Cramlin
3                      Troy

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Senior Director of Technologyy
This should do what you want.  The group by is what makes the query sum up revolving around the group_id.  Keep in mind any time you do a group by, the column you group on has to be one of the columns you select in the query.

select(count(*)), group_id from Teams group by group_id

Open in new window

awking00Information Technology Specialist

select group_id, count(name)
from teams
group by group_id
order by group_id;
awking00Information Technology Specialist

Sorry, Jeffrey. I didn't refresh my screen before I posted.


Thank you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial