Results 1 to 4 of 4
  1. #1
    sepoto is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2011
    Posts
    3

    A query with Sum() and how to add more fields to it.



    Code:
    SELECT FullCityName, Sum(Population)
    FROM Duplicates
    GROUP BY FullCityName;
    I tried adding another field:

    Code:
    SELECT FullCityName, ZipCode, Sum(Population)
    FROM Duplicates
    GROUP BY FullCityName;
    Do I have to use a join? If so what would the structure have to look like? I'm wondering why does "FullCityName," result in a functional query but "FullCityName, ZipCode" result in an "aggregate function" error? I need to get this down.


  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Any field in the select clause that is not aggregated (Sum, Avg, Max, etc) needs to be in the GROUP BY clause. Try


    SELECT FullCityName, ZipCode, Sum(Population)
    FROM Duplicates
    GROUP BY FullCityName, ZipCode
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    sepoto is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Apr 2011
    Posts
    3
    That is the answer. It works very well.

    Code:
    SELECT FullCityName, ZipCode, Sum(Population)
    FROM Duplicates
    GROUP BY FullCityName, ZipCode;

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Happy to help.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 12
    Last Post: 05-07-2012, 12:41 PM
  2. Query on 9 Fields
    By qbc in forum Queries
    Replies: 1
    Last Post: 01-21-2012, 10:42 PM
  3. Replies: 11
    Last Post: 09-15-2011, 03:52 PM
  4. Replies: 2
    Last Post: 03-23-2011, 11:13 AM
  5. Basic Query/totaling fields in a query
    By afisher in forum Queries
    Replies: 6
    Last Post: 08-05-2010, 01:43 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums