Results 1 to 4 of 4
  1. #1
    gameemaster is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2016
    Posts
    23

    How To Do A Rank Query With a Group By Clause


    I have about 50 branches, each branch has like hundreds of invoices. I want to rank from like 1 to 10 which branch has the most invoices, the query Im using below does not work? Can anyone assist? I just need to Group By the Branch, show the number of invoices at the branch, and rank them accordingly, can anyone help?

    SELECT A.Branch, Count(InvoiceNumber) AS Rank
    FROM tbl_SR_Posting_Error AS A INNER JOIN tbl_SR_Posting_Error AS B ON A.Branch = B.Branch AND A.InvoiceNumber >=B.InvoiceNumber
    GROUP BY A.Branch, A.InvoiceNumber

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Ranking in query is a common topic. Have you searched? This not easy to do.

    http://allenbrowne.com/ranking.html

    Why bother assigning a ranking value?
    Maybe you should just return the TOP 10?

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


    Build the GROUP BY query then use that as source for TOP 10 query.
    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
    gameemaster is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Sep 2016
    Posts
    23
    Thanks so much for your reply. I like challenges; I will try the rank query, if not, I will use Top 10. I appreciate the top values idea a lot. Take care.

  4. #4
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,716

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

Similar Threads

  1. Rank Within Group Query
    By wcrimi in forum Queries
    Replies: 11
    Last Post: 11-04-2015, 08:41 PM
  2. Rank Query
    By cbritt927 in forum Queries
    Replies: 2
    Last Post: 06-02-2015, 04:42 PM
  3. Query Rank
    By DHIGHTO in forum Queries
    Replies: 14
    Last Post: 01-12-2015, 02:59 PM
  4. SELECT & GROUP BY Clause
    By johnseito in forum Access
    Replies: 5
    Last Post: 07-11-2014, 10:55 PM
  5. Replies: 6
    Last Post: 07-24-2012, 03:02 PM

Tags for this Thread

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