Results 1 to 4 of 4
  1. #1
    lily.hansen is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2011
    Posts
    2

    Query top-three producers

    I'm wondering if there is a way to do a "top three" sort of query. For instance, we have 83 facilities that we manage. Each facility has different departments. I want to be able to tell which three departments have the most number of records within each facility. Is there a way to craft a query that will give the results for the sub-groups with the most records? I would like the final report to look something like:

    A. Facility A
    i. Department with most records (count records within that department)


    ii. Department with second most records
    iii. Department with third most records
    B. Facility B
    i. and so on

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    see Top n Per Group here
    http://allenbrowne.com/subquery-01.html

  3. #3
    lily.hansen is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Dec 2011
    Posts
    2
    Thank you, but the TOP n just displays the most recent entries for a query. I want it to count the number of records in a certain group and organize by how many records are in each, and then exclude from the results and records that are least represented by the data. i.e., one department has 50 complaints, another has 38, another has 21, and the others have less. I want only the ones with 50, 28, and 21 complaints to show up, because the other departments have less complaints than they do.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    Well that reference gives you the general syntax, and explains the concept. I thought that was a good place to start.

    What query have you tried? Can you show us the sql? What part exactly is the issue?
    If you want someone to write the query for you, you're going to have to supply table structures, relationships and some sample data.

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

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