Results 1 to 5 of 5
  1. #1
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83

    Max of Count Query

    I am trying to find the Maximum value of a count query below. Each employee can see multiple customers and I want to return only the employee who had the highest count per customer. For example, emplyee ID #1, 2, and 3 saw customer #1 10, 20 and 30 times respectively. I only want to return employee ID #3 in my query for that particular customer (so on and so forth). The query below does not work because the Max function returns employees 1,2 and 3 because they have different numbers. Any help is appreciated. Thanks



    Code:
    SELECT aCount.[EmployeeID], Max(aCount.[Panel Size]) AS [Highest]
    
    FROM (SELECT [EmployeeID], tbl1.[CustomerID], Count([CustomerID]) AS [Panel Size]
    FROM tbl1
    GROUP BY [EmployeeID], CustomerID])  AS aCount
    
    GROUP BY [EmployeeID]

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,602
    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
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83
    I am not sure if this will work (I have tried this solution but i cannot include the "WHERE" in the criteria subquery because i am working with a flat file in access, so I do not have associated tables to lookup in the criteria). Do you have any other suggestions?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,602
    Works with one table. Review these:

    http://allenbrowne.com/subquery-01.html
    http://allenbrowne.com/ranking.html

    Probably should have pointed you to Allen Browne right off.
    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.

  5. #5
    dssrun is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    83
    sorry for the late reply, i was side tracked. THanks for the help!

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

Similar Threads

  1. Count Query
    By athomas8251 in forum Queries
    Replies: 11
    Last Post: 12-12-2011, 06:46 PM
  2. Query with max value and max count
    By Fabdav in forum Queries
    Replies: 1
    Last Post: 10-13-2011, 07:14 AM
  3. Conditional count in query
    By jbr87 in forum Queries
    Replies: 1
    Last Post: 09-27-2011, 12:06 PM
  4. count query
    By lmp101010 in forum Access
    Replies: 6
    Last Post: 08-02-2010, 02:31 PM
  5. count query
    By lmp101010 in forum Queries
    Replies: 1
    Last Post: 08-01-2010, 12:20 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