Results 1 to 4 of 4
  1. #1
    PeggyMcP is offline Novice
    Windows 2K Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    2

    Access2010 SQL syntax to Average and Count result

    I am trying to run this query, but the results are always just the count; the average part doesn't happen.


    Code:
    SELECT [Rater Type], AVG(RaterTypeCount) From
        (select [Rater Type], Count(*) as RaterTypeCount
          From RatersPerParticipants
          where LOB="Product Sale" and [Rater Type]="Boss"
          Group by [Rater Type] )
    Group by [Rater Type]
    Table
    LOB Rater Type # of Raters

    a Plain count of "Product Sale" "Boss" (below) returns the same value as above

    Code:
    SELECT Count([Rater Type]) as RaterCount
    From RatersPerParticipants
    where LOB="Product Sale" and [Rater Type]="Boss"

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Because the outer query is selecting and grouping on the [Rater Type] field. Maybe you want:

    SELECT AVG(RaterTypeCount) As AvgCount From
    (SELECT [Rater Type], Count(*) AS RaterTypeCount
    FROM RatersPerParticipants
    WHERE LOB="Product Sale" AND [Rater Type]="Boss"
    GROUP BY [Rater Type]) AS Q1;
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    PeggyMcP is offline Novice
    Windows 2K Access 2010 32bit
    Join Date
    Apr 2013
    Posts
    2
    Thanks, June7! Minutes after stepping away from the puzzle I also realised that I was counting the wrong field. If I couund the number of raters like I should, then I think I can select the rater type to identify the averages and the avg will work. Just a bonehead blunder. Thanks for your gentle reply (I'm new to using forums).

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,625
    Count() isn't using a particular field, doesn't have to since what is counted is records. Did you mean you were grouping on the wrong field?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 30
    Last Post: 08-15-2012, 02:25 PM
  2. Replies: 3
    Last Post: 08-03-2012, 02:37 AM
  3. Count Unique Fields and then get Average
    By Kirsti in forum Queries
    Replies: 5
    Last Post: 02-19-2012, 07:25 PM
  4. Access2010 problem with .close
    By jong in forum Access
    Replies: 1
    Last Post: 11-18-2010, 12:53 PM
  5. Result of Count Query not known elsewhere
    By Carole in forum Access
    Replies: 1
    Last Post: 09-07-2008, 09:39 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