Results 1 to 3 of 3
  1. #1
    springboardjg is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2011
    Location
    Milton Keynes
    Posts
    10

    SQl - Average Function

    Hi



    I have an INNER JOIN query that returns all the data sets that I need from two different tables. However, I am trying to AVERAGE a columnn retrieved from the second table and GROUP BY a column retrieved from the first table. But am getting the following error...

    "You tried to execute a query that does not include the specified expression 'Site_Serial' as part of an aggregate function"

    Here is the SQL Query causing this error...

    Code:
    SELECT tbl_SiteInformation.Average_Grouping, tbl_SiteInformation.Site_Serial, tbl_SiteSerialsAndWeeklyAverages.HSI_Year, tbl_SiteSerialsAndWeeklyAverages.HSI_Month, AVG(tbl_SiteSerialsAndWeeklyAverages.Weekly_Average) AS MoMCurrentMonth
    FROM tbl_SiteInformation INNER JOIN tbl_SiteSerialsAndWeeklyAverages ON tbl_SiteInformation.Site_Serial = tbl_SiteSerialsAndWeeklyAverages.Site_Serial
    WHERE tbl_SiteSerialsAndWeeklyAverages.HSI_Year = 2011
    AND tbl_SiteSerialsAndWeeklyAverages.HSI_Month = 4
    AND (tbl_SiteSerialsAndWeeklyAverages.Weekly_Average IS NOT NULL)
    AND (SELECT tbl_SiteSerialsAndWeeklyAverages.Weekly_Average
    FROM tbl_SiteSerialsAndWeeklyAverages AS tbl_SiteSerialsAndWeeklyAveragesAlias
    WHERE tbl_SiteSerialsAndWeeklyAverages.Site_Serial = tbl_SiteSerialsAndWeeklyAveragesAlias.Site_Serial AND tbl_SiteSerialsAndWeeklyAveragesAlias.HSI_Year=2011 AND tbl_SiteSerialsAndWeeklyAveragesAlias.HSI_Month=3 AND tbl_SiteSerialsAndWeeklyAveragesAlias.Weekly_Average IS NOT NULL)
    GROUP BY Average_Grouping;
    Any help would be greatly appreciated. I can also post the results returned by the query if the AVG function and the GROUP BY are excluded.

    Thanks

    James

  2. #2
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,171
    Hi,

    if you use a group by instruction, each member of the SELECT statement has to be part of the group by statement or have an aggregation function.

    greetings
    NG

  3. #3
    Rhino373 is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    May 2011
    Posts
    65
    So assuming there is only 1 site_serial when grouping by Average_Grouping just group by first for that column. If it could return multiple then you would group by it as well unless it's a number in which case you'll have to either exclude it altogether or use a math function like sum.

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

Similar Threads

  1. How to do an average report
    By MattyB in forum Reports
    Replies: 0
    Last Post: 04-11-2011, 02:09 AM
  2. Average function
    By rahayes in forum Queries
    Replies: 1
    Last Post: 04-10-2011, 02:44 PM
  3. Average help please
    By C90RanMan in forum Programming
    Replies: 1
    Last Post: 08-01-2010, 12:14 PM
  4. Replies: 13
    Last Post: 05-28-2010, 11:57 AM
  5. Property Sheet Average Function How to do?
    By techexpressinc in forum Reports
    Replies: 2
    Last Post: 06-25-2009, 11:10 AM

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