2

我需要查询一个人在办公室内停留的时间。我有一个列表,该列表创建了一个人何时进入办公室的记录,以及该人何时离开办公室的记录和其他记录。我有一些困难,因为一个人可以在同一天多次进出,有时一个人没有注册您的进出。根据例子

╔════════════╦════════════╦════════════════════╦═════════════════╦═════════╦═══════╗
║ Local Date ║ Local Time ║      Employee      ║     Office      ║ Catraca ║ Staus ║
╠════════════╬════════════╬════════════════════╬═════════════════╬═════════╬═══════╣
║ 11/7/2012  ║ 10:16      ║ SILVA ,ANDRE BRAGA ║ Alexandre Duma  ║     002 ║ In    ║
║ 11/7/2012  ║ 13:03      ║ SILVA ,ANDRE BRAGA ║ Alexandre Dumas ║     004 ║ Out   ║
║ 11/7/2012  ║ 15:19      ║ SILVA ,ANDRE BRAGA ║ Alexandre Dumas ║     004 ║ Out   ║
║ 11/7/2012  ║ 15:25      ║ SILVA ,ANDRE BRAGA ║ Alexandre Dumas ║     004 ║ In    ║
║ 11/7/2012  ║ 18:31      ║ SILVA ,ANDRE BRAGA ║ Alexandre Dumas ║     004 ║ Out   ║
║ 11/7/2012  ║ 18:40      ║ SILVA ,ANDRE BRAGA ║ Alexandre Dumas ║     004 ║ In    ║
║ 11/7/2012  ║ 19:56      ║ SILVA ,ANDRE BRAGA ║ Alexandre Dumas ║     004 ║ Out   ║
╚════════════╩════════════╩════════════════════╩═════════════════╩═════════╩═══════╝

在这个例子中,这个人在办公室的时间是 07:09

Regads 安德烈

4

1 回答 1

0

好的,合计起来相当容易。消除没有匹配时间戳的时间戳更加困难。

至于总计:日期和时间在内部存储为数字。假设没有人在午夜工作,那么您所要做的就是将所有“In”时间相加并从所有“Out”时间中减去。像这样:

SELECT [TotOut]-[TotIn] AS TotHours, *
FROM (SELECT CheckIn.Employee, CheckIn.[Local Date], Sum(CheckIn.[Local Time]) AS [TotIn]
FROM CheckIn
WHERE (((CheckIn.Staus)="In"))
GROUP BY CheckIn.Employee, CheckIn.[Local Date])  AS TotIn INNER JOIN (SELECT CheckIn.Employee, CheckIn.[Local Date], Sum(CheckIn.[Local Time]) AS [TotOut]
FROM CheckIn
WHERE (((CheckIn.Staus)="Out"))
GROUP BY CheckIn.Employee, CheckIn.[Local Date])  AS TotOut ON (TotIn.Employee = TotOut.Employee) AND (TotIn.[Local Date] = TotOut.[Local Date]);

消除不匹配的时间是可能的,但很困难。这个查询完成了大部分工作。但是,它跳过了第一条记录,因此需要调整。

SELECT A.ID, A.[Local Time], B.[Local Time] AS [Prev Time], A.Staus
FROM CheckIn AS A LEFT JOIN CheckIn AS B ON (A.Employee = B.Employee) AND (A.[Local Date] = B.[Local Date])
WHERE (((B.[Local Time])=DMax("[local time]","[checkin]","[local time] < #" & [a].[Local Time] & "#")) AND ((A.Staus)<>[b].[staus]))
ORDER BY A.[Local Time];

此外,您需要首先创建一个记录集,该记录集会跳过任何以“Out”状态开头的记录。这是一篇可能会有所帮助的文章

于 2012-12-14T05:43:55.810 回答