Solved

Need your help with Query in access

Posted on 2014-01-09
1
206 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

623 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