On 04 Nov 2004 13:26:54 GMT, Shobhit Shanker
<shobhit_shanker@hcm.honda.com> declaimed the following in
comp.databases.ms-access:
> Hey John,
>
> Thanks a LOT for your code. It did EXACTLY what I wanted!
I definitely need more practice with sub-selects -- especially
when they appear in the list of "output fields" rather than in join or
where clauses...
The best I'd come up with was:
ID CheckID Date
1 18 9/2/2003
2 18 10/1/2004
3 18 10/20/2004
4 18 10/29/2004
5 19 10/20/2003
6 19 8/29/2004
7 19 9/29/2004
8 19 10/15/2004
9 19 7/29/2004
SELECT tc.CheckID, tc.Date, (tc.Date+Elapsed) AS CheckDate,
(min(tc1.Date-tc.Date)) AS Elapsed
FROM tblCheck AS tc LEFT JOIN tblCheck AS tc1 ON tc.CheckID=tc1.CheckID
WHERE tc.Date<tc1.Date
GROUP BY tc.CheckID, tc.Date
ORDER BY tc.CheckID, tc.Date;
CheckID Date CheckDate Elapsed
18 9/2/2003 10/1/2004 395
18 10/1/2004 10/20/2004 19
18 10/20/2004 10/29/2004 9
19 10/20/2003 7/29/2004 283
19 7/29/2004 8/29/2004 31
19 8/29/2004 9/29/2004 31
19 9/29/2004 10/15/2004 16
Which, as you can see, doesn't show the "0" elapsed lines, and
has the misfortune of needing the prior date record...
> ============================================================== <
> wlfraed@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
> wulfraed@dm.net | Bestiaria Support Staff <
> ============================================================== <
> Home Page: <http://www.dm.net/~wulfraed/> <
> Overflow Page: <http://wlfraed.home.netcom.com/> <