Results 1 to 7 of 7
  1. #1
    boutwater is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    6

    more aggregate function questions


    I'd like to do this:
    SELECT Month, itemnumber, max(cartoncount)
    FROM cartonsBySKUPerMonth
    GROUP BY itemnumber
    ORDER BY ItemNumber

    but it complains about the "Month". How can I show this? Thanks,

    Ben

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Because Month is an Access Reserved Word, you need to put it in square brackets (a good reason to avoid using Access Reserved Words and spaces in your object or field names).

    SELECT [Month], itemnumber...etc.

  3. #3
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    I normally use the field type as the first 3 characters of the fieldname that way it'll never be a reserved word.

    Your month would be intmonth.

  4. #4
    boutwater is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    6
    I put it in brackets, but still get the error complaining that "Month" isn't an aggregate function. I know it isn't, but i wasn it displayed when the max is returned so i know which month the max occurred in.

  5. #5
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    You need to include MONTH in the Group By clause.

  6. #6
    boutwater is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2011
    Posts
    6
    I dion't want to group by the Month though...i just want it to show up based on what I am grouping by.

  7. #7
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by boutwater View Post
    I dion't want to group by the Month though...i just want it to show up based on what I am grouping by.
    With a Group By Clause you either have to include that field in it or it can't be included in the query.

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

Similar Threads

  1. aggregate error due to function
    By boutwater in forum Access
    Replies: 2
    Last Post: 09-26-2011, 03:39 PM
  2. Aggregate function returns duplicate values
    By lokiluke in forum Queries
    Replies: 3
    Last Post: 09-16-2011, 09:40 AM
  3. Replies: 0
    Last Post: 04-25-2011, 07:58 PM
  4. an aggregate function error message
    By newtoAccess in forum Queries
    Replies: 1
    Last Post: 11-27-2010, 05:18 PM
  5. Access SQL Query - Aggregate function
    By jack in forum Access
    Replies: 0
    Last Post: 11-10-2009, 08:06 PM

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