Results 1 to 4 of 4
  1. #1
    leobear is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Jan 2012
    Posts
    4

    Ranking (Look for previous ranking)

    ID Sales Date Sales
    1 A 201101 8
    2 B 201101 7
    3 C 201101 7
    4 D 201101 6
    5 A 201102 3
    6 B 201102 4
    7 C 201102 6
    8 D 201102 7


    9 A 201103 2
    10 B 201103 8
    11 C 201103 4
    12 D 201103 5

    Hi I have a table look like this and I have created a ranking sql.
    SELECT a.SalesPerson, a.Sales, (Select count(*) from Table1 as b where
    b.sales > a.sales and b.date = a.date ) + 1 AS rank, a.date
    FROM Table1 AS a
    ORDER BY sales DESC;
    The question now I have is how can I look for previous ranking in the
    same query?
    i.e. in 201103 "B" previous ranking is 3 which come from the data of
    201102.
    and for 201101, how can I tell SQL to get the data from 201012?
    Thanks.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The previous ranking for 201103 B is from 201102 A, not B? Would the previous ranking for 201103 D be from 201102 C?
    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
    leobear is offline Novice
    Windows 7 64bit Access 2003
    Join Date
    Jan 2012
    Posts
    4
    Hi June,

    The previous ranking for B is still B but the date is one period backward.

    I am not sure if how I can calculate the previous rank in the same query of below.

    SELECT a.SalesPerson, a.Sales, (Select count(*) from Table1 as b where
    b.sales > a.sales and b.date = a.date ) + 1 AS rank, a.date
    FROM Table1 AS a
    ORDER BY sales DESC;

    Thanks.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Check this tutorial for calculation between records http://allenbrowne.com/subquery-01.html#AnotherRecord
    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.

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

Similar Threads

  1. ranking: can i query a report?
    By stevepcne in forum Reports
    Replies: 2
    Last Post: 11-20-2011, 01:03 AM
  2. Totaling and ranking results in queries
    By dmellman in forum Access
    Replies: 8
    Last Post: 08-06-2011, 12:26 PM
  3. Grouping, Summing, and Ranking Problem
    By cadsvc in forum Reports
    Replies: 3
    Last Post: 04-16-2011, 11:34 AM
  4. Ranking and assigning a Value
    By loopyl00 in forum Access
    Replies: 0
    Last Post: 01-11-2011, 12:14 PM
  5. Help to build a ranking
    By chorbi26 in forum Access
    Replies: 0
    Last Post: 12-20-2010, 12:47 PM

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