Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need your help with Query in access

Posted on 2014-01-09
1
Medium Priority
?
208 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 27

Accepted Solution

by:
Shaun Kline earned 2000 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

877 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