[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Display the last "n" records before the last in a MS Access Query

Posted on 2012-09-19
3
Medium Priority
?
401 Views
Last Modified: 2012-09-19
Hello

I have a table/query that lists the daily prices for particular commodities.  The query is called qry_Prices and contains the following fields:

Commodity_Name
Price_Date
Price_Amount

What I want to do is ultimately create a report/graph that shows the price movement over the past 10 days from the last inputted date for each commodity (don't worry too much about whether each commodity will have a differenct "last" date.  This is not the case since prices are inputted for each commodity daily so the last date will always be the same).  The last inputted date always is the last record.

The results in the query will obviously "roll" since I will be entering a price everyday so I need something like:

[Last Entered Date] - 10

So, in summary I would like to see:

Commodity_Name
Price_Date
Price_Amount

where the date range is between the [LastDate/Record] and [LastDate/Record] - 10.

Hope that you can help!
0
Comment
Question by:staceymoore
  • 2
3 Comments
 
LVL 31

Accepted Solution

by:
hnasr earned 2000 total points
ID: 38414958
Try this for table a(f1, f2, dttm1)

SELECT a.f1, a.f2, a.dttm1
FROM a
where a.dttm1 between (select max(a.dttm1) from a)-10  and (select max(a.dttm1) from a)  ;

Open in new window

0
 

Author Closing Comment

by:staceymoore
ID: 38415306
thanks again for your assistance!
0
 
LVL 31

Expert Comment

by:hnasr
ID: 38416139
Welcome!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question