Use a subquery to get the nearest prior time
If subqueries are new, here's an example:
Subquery basics: Get the value in another record
at:
http://allenbrowne.com/subquery-01.html#AnotherRecord
These were all good answers. I tried Allen Browne's suggestion using
a subquery. Is it possible to do this by parameters comparing two
rows like test1 and test4 within a subquery. I'd like to avoid
creating a function or another query. This is what I have so far:
SELECT atom.xAN, atom.xStartTime, atom.xText, (SELECT TOP 1
Dupe.xStartTime
FROM atom AS Dupe
WHERE Dupe.xStartTime < atom.xStartTime
ORDER BY Dupe.xStartTime DESC, Dupe.xAN) AS PriorStartTime,
[ElapsedSeconds]/60 AS ElapsedMinutes, DateDiff("s",[PriorStartTime],
[xStartTime]) AS ElapsedSeconds, [xStartTime]-[PriorStartTime] AS
ElapsedTime_01
FROM atom;
Which gives me this:
xAN xStartTime xText PriorStartTime ElapsedMinutes ElapsedSeconds
ElapsedTime_01
1 9/22/2007 3:29:15 AM test
2 9/22/2007 3:29:17 AM test1 9/22/2007 3:29:15 AM 0.03 2
2.31481535593048E-05
3 9/22/2007 3:29:20 AM test2 9/22/2007 3:29:17 AM 0.05 3
3.47222230629995E-05
4 9/22/2007 3:29:22 AM test3 9/22/2007 3:29:20 AM 0.03 2
2.31481462833472E-05
5 9/22/2007 3:29:26 AM test4 9/22/2007 3:29:22 AM 0.07 4
4.62962925666943E-05
6 9/22/2007 3:29:29 AM test5 9/22/2007 3:29:26 AM 0.05 3
3.47222230629995E-05
9 9/22/2007 9:10:57 AM test6 9/22/2007 3:29:29 AM 341.47 20488
0.237129629633273
10 9/22/2007 9:11:57 AM test7 9/22/2007 9:10:57 AM 1.00 60
6.94444439432118E-04
11 9/22/2007 10:11:57 AM test8 9/22/2007 9:11:57 AM 60.00 3600
4.16666666715173E-02