If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Query
I have a table in which I have 2 items.
Eg Table Sales 2/22 100 2/23 90 I need to show the difference between the days 2/22 and 2/23. I am drawing a blank. Can someone help me out. Thanks |
#2
|
|||
|
|||
Hi,
Assuming you have a date_time field, dt, then SELECT a.dt, LAST(b.sales)-LAST(a.sales) FROM (myTable As a INNER JOIN myTable As b ON a.dt b.dt) INNER JOIN myTable As c ON a.dt c.dt GROUP BY a.dt, b.dt HAVING MIN(c.dt)= b.dt Basically, we got three references to the original data. we group on each date_time of a, each date_time of b that are occurring after a, and let c.dt floating. When the groups are made, (with all possible combinations of a.dt and b.dt), we keep only those where b.dt = MIN(c.dt), ie, only those of b.dt immediately following a.dt. There is a rule telling that we must either include the field in the group by, either aggregate it, so here, we use LAST over the sales fields, to get the single value associated to a given reference a, or b. Hoping it may help, Vanderghast, Access MVP wrote in message ... I have a table in which I have 2 items. Eg Table Sales 2/22 100 2/23 90 I need to show the difference between the days 2/22 and 2/23. I am drawing a blank. Can someone help me out. Thanks |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
query wizard error | Christen | General Discussion | 12 | August 13th, 2004 08:37 PM |
Query to join records form 2 databases | bdehning | General Discussion | 5 | August 9th, 2004 03:09 PM |
Display Parameter from Form on Report | sara | Setting Up & Running Reports | 10 | July 19th, 2004 04:54 PM |
SELECT function in Query | alexparks | Running & Setting Up Queries | 9 | July 5th, 2004 11:31 AM |
query field reference help | -dch | Running & Setting Up Queries | 4 | June 2nd, 2004 07:30 PM |