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