Where is Rank Function in Access 2007?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SLK836
    New Member
    • Sep 2012
    • 1

    #1

    Where is Rank Function in Access 2007?

    I am trying to derive rank values in a query, just as one would with the Rank function in Excel. I use MS Access 2007 and want to build a query that will do it. I know how to build queries to give me only the top N but I don't want to have to build multiple queries for this request.
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3665

    #2
    SLK836,

    As far as I know there is no Rank function (an incredible life saver in Excel!) in MS Access. However, what I have done is create a query. Then based on the results of that query, I create another query based on the same fields, and count how many records are above the current recordds based on the criteria of the current record.

    For example, if you had a list of employees with their current salary, you would use the current record and count how many records in the current dataset have salaries greater than the current one. Then you add 1 (i.e. the highest salary will have zero records greater). This also accounts for ties, so that if record 3 and 4 are tied, they both receive 3's, but the next record is a 5.

    Not sure if this makes sense, but without your data, and without writing your queries for you, this will get you in the right direction. I'll be glad to work through additioinal details....

    Comment

    • zmbd
      Recognized Expert Moderator Expert
      • Mar 2012
      • 5501

      #3
      Two examples:

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Subqueries are one way of doing it. They're slower but easier to understand.

        You can also accomplish a similar result by joining the table to itself. It's faster but slightly more difficult to set up.

        Comment

        • zmbd
          Recognized Expert Moderator Expert
          • Mar 2012
          • 5501

          #5
          Ranking data

          SLK836:

          Rabbit's suggestion of the self join would more than likely be the best solution.

          Because you didn't post any data, I did not suggest the self join due to the potential difficulties in setting up the query and instead offered the other two methods.

          I say, have a go at the self join and let us know how you fair... in either case (good or bad) please post your SQL so that we can either help or tune it!

          Best of Luck

          Comment

          Working...