开发者

Calculate average date difference between records in MS Access

I have a list on when items have been handed out. The table has the following structure:

  • primary key - autonumber itemname
  • itemid - number
  • datehandedout - date/time

I want to calculate the average length of time betw开发者_如何学JAVAeen when one object is given out and the next one is given out. There will be a number of different items for which the average time between handouts needs to be listed for.

So something like (pseudocode):

average( [thisrecord]![datehandedout] - [lastrecord]![datehandedout] )

Any help will be much appreciated.


This is a very slow query:

SELECT Avg(DateDiff("h",[datehandedout],(
    SELECT TOP 1 datehandedout 
    FROM tbl tx 
    WHERE tx.datehandedout > t.datehandedout))) AS Difference
FROM tbl AS t

Add another Where statement to limit the number of records returned when you test, for example:

WHERE Year([datehandedout])=2010
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜