Grouping Data in a Query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

A query with two fields.

Field 1 = Name
Field 2 = Amount

How do you group the query by name & add up the amounts. What code would
you use so it grabs those records with the same name and adds up those
amounts.

For example, records as follow:

Curtis | $1.00
Mike | $2.00
Curtis | $2.50
Curtis | $2.50

It would then spit out

Curtis | $6.00
Mike | $2.00
 
Open up the query in design mode
Select View: Totals from the menu
Change GROUP By To SUM under the Amount field
Leave Group by as Group By under the name field.

Run the query.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
What if they are several other fields? I was trying to keep my question
simple & modify the answers, but not able to get it to work.
 
It depends on what you want from those other fields.

Grouping controls the sum. That is SUM is performed over the group as
identified by the grouping fields.

You can use a separate query to get the sum for the group and then add that
query to your existing query to show the sum for each name. It will show
the sum on each of the multiple lines for Curtis and Mike.,

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
Back
Top