Results 1 to 3 of 3
  1. #1
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168

    Need maximum value from count query for group.

    Ok .. I don't know if I can explain it, so it may just be easier to display what I am talking about and my SQL.



    I have a query that gives me counts for each group ... fine, however I really just want the TOP 1 count for each group. I know .. there can be duplicate counts .. and in that case I would be ok with showing all of the values that are acceptable.

    This is my SQL for the below ... but I would like to limit it to only the TOP 1 count.

    For example below .. I only want to see the ETS Test records with count of 33 transmissions and ETS LRT Training with count of 450, so really only 1 record per group, unless there is a tie .. then I want to see all the tied records.





    SELECT Kevin.User, Transmissions.Type, Transmissions.Group, KevinGroup.Name, Transmissions.Radio, Count(*) AS CountOfGroup1
    FROM Kevin RIGHT JOIN (Transmissions LEFT JOIN KevinGroup ON Transmissions.Group = KevinGroup.Group) ON Kevin.Radio = Transmissions.Radio
    GROUP BY Kevin.User, Transmissions.Type, Transmissions.Group, KevinGroup.Name, Transmissions.Radio
    ORDER BY Count(*) DESC;

    User Type Group Name Radio CountOfGroup1
    Harris Tech Radio * Tr 65 ETS Test 16013 6
    ETS Radio Tech * Tr 65 ETS Test 15813 1
    Harris Tech Radio * Tr 65 ETS Test 16014 33
    ETS Console * Tr 65 ETS Test 15019 13
    ETS Console * Tr 65 ETS Test 15017 9
    ETS Bus * Tr 65 ETS Test 13934 3
    ETS Bus * Tr 65 ETS Test 14064 1
    ETS Bus * Tr 65 ETS Test 13652 1
    ETS Signals * Tr 67 ETS Lrt Training 15974 450
    ETS Lrt Signals * Tr 67 ETS Lrt Training 15923 5
    ETS Bus * Tr 67 ETS Lrt Training 15925 17
    ETS Lrt Signals * Tr 67 ETS Lrt Training 15973 284
    ETS LRT Signals * Tr 67 ETS Lrt Training 15684 198
    ETS Bus Control * Tr 67 ETS Lrt Training 15004 2
    ETS Signals * Tr 67 ETS Lrt Training 15917 1
    ETS Lrt Maintenance * Tr 67 ETS Lrt Training 15930 27
    ETS LRT Train * Tr 67 ETS Lrt Training 15901 8

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,628
    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
    edmscan is offline Competent Performer
    Windows 8 Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    168
    Got it to work .. with help from another forum. Just for others .. this may help as this is exactly what I was trying to accomplish and it works just fine.

    http://www.utteraccess.com/forum/Max...-t1702155.html

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

Similar Threads

  1. COUNT Group Count Records COUNT FUNCTION
    By PMCOFFEY in forum Access
    Replies: 9
    Last Post: 11-09-2012, 09:40 PM
  2. Replies: 3
    Last Post: 04-19-2012, 01:22 PM
  3. nested query: avg, count, group by
    By gap in forum Queries
    Replies: 2
    Last Post: 07-05-2011, 07:48 AM
  4. Replies: 0
    Last Post: 04-25-2011, 07:58 PM
  5. Query to group and count field entries
    By newtoAccess in forum Queries
    Replies: 4
    Last Post: 11-29-2010, 09:19 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