Results 1 to 2 of 2
  1. #1
    ahudson is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2013
    Posts
    1

    Select last four occurences only


    Hi, I've been scratching my head over this for a couple of days now but can't seem to see a way around it!
    We run events and have various tickets outlets for each event. We monitor sales on a weekly basis and provide monthly feedback to the management. I therefore have EventID, SellerID and WeeklySales as fields. I am stumped at how to select only the last four weeks sales for a particular seller and to total these. Apologies if this is simplistic but Access is quite new to me and I'm a bit out of my depth with the selection of only the last four weeks part.

    Thanks

  2. #2
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    The simplest way is to simply include a date range in the WHERE Clause of your SQL String.

    Code:
    SELECT 
        [EventID], 
        [SellerID], 
        [WeeklySales] 
    FROM 
        MyTable 
    WHERE 
        [Timestamp] BETWEEN Date() AND DateAdd("w", -4, Date())
    This assumes that you're storing the date in your Table, of course. If you're not, you should think about adding that in since you're at the mercy of the Table when it comes to ordering Records: Generally it's first-in, first-out, but that's not always the case (so a record you added today could appear BEFORE a Record you added yesterday).

    Anyway, if you're not including the date in your Table, then you can just limit the results to the first 4 Records (or however many you need):
    Code:
    SELECT 
        TOP 4 
        [EventID], 
        [SellerID], 
        [WeeklySales] 
    FROM 
        MyTable

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

Similar Threads

  1. Replies: 5
    Last Post: 07-26-2012, 12:59 PM
  2. Count occurences of text in a query
    By funkygoorilla in forum Queries
    Replies: 5
    Last Post: 02-12-2012, 09:14 PM
  3. Replies: 8
    Last Post: 04-21-2011, 05:29 PM
  4. Counting text occurences
    By katie_88 in forum Queries
    Replies: 3
    Last Post: 07-19-2010, 10:46 AM
  5. Need Help counting occurences
    By anyoder in forum Queries
    Replies: 0
    Last Post: 03-09-2007, 08:53 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