Solved

Need your help with Query in access

Posted on 2014-01-09
1
202 Views
Last Modified: 2014-01-11
Rec#      LookUpDate      Amount1                      Amount2
58      9/23/2013      72,599.00      33,795.00
59      10/23/2013      75,753.00      35,063.00
60      11/8/2013      75,046.00      35,063.00
61      12/9/2013      78,256.00      35,700.00
62      1/8/2014                       80,615.00      36,340.00

 twice a month, i input two amounts :Amount1      and Amount2      in the database,
how to write a query to see the difference in last and previous records, in case like this should be:
RecentDate               Diff1                  Diff1
1/8/2014                       2,359.00                 640.00
0
Comment
Question by:rfedorov
1 Comment
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 total points
ID: 39768652
You can use a sub query in your select clause to find the prior row:

select LookupDate, Amount1, Amount2, 
   (select top 1 Amount1 from <yourtable> b where b.LookupDate < a.LookupDate Order by b.LookupDate Desc) AS PriorAmount1,
  (select top 1 Amount2 from <yourtable> b where b.LookupDate < a.LookupDate Order by b.LookupDate Desc) AS PriorAmount2
from <yourtable> a

Open in new window


For large data sets, this query may take time to return.
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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

680 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