2

我正在尝试使用在 Microsoft Access 数据库中创建的现有数据库。该数据库有一个表CHECKINOUT,该表存储每个用户的指纹检查时间的数据,顺序如下-

USERID         CHECKTIME        CHECKTYPE            VERIFYCODE
=======================================================
3         10/03/2013 7:03:32 PM   I             1   
3         10/03/2013 11:45:49 AM  I             1
3         10/03/2013 8:40:20 AM   I             1
3         11/03/2013 7:13:33 PM   I             1
3         11/03/2013 11:24:36 PM  I             1
3         11/03/2013 9:04:42 AM  I              1
4         10/03/2013 7:02:46 PM   I             1
4         10/03/2013 6:43:10 PM   I             1
4         10/03/2013 10:46:41 AM  I             1
4         10/03/2013 8:47:04 AM   I             1
4         11/03/2013 7:23:33 PM   I             1
4         11/03/2013 11:20:36 PM  I             1
4         11/03/2013 8:28:42 AM  I              1

现在,让我手动选择最小和最大时间。

10 March UserID(3) Maximum Time: 10/03/2013 7:03:32 PM
10 March UserID(3) Minimum Time: 10/03/2013 8:40:20 AM
11 March UserID(3) Maximum Time: 11/03/2013 7:13:33 PM
11 March UserID(3) Minimum Time: 11/03/2013 9:04:42 AM


10 March UserID(4) Maximum Time: 10/03/2013 7:02:46 PM
10 March UserID(4) Minimum Time: 10/03/2013 8:47:04 AM
11 March UserID(4) Maximum Time: 11/03/2013 11:20:36 PM
11 March UserID(4) Minimum Time: 11/03/2013 8:28:42 AM

现在我想编写一个查询来使用phpCHECKTIME从表中的列中选择个人(例如,UserID = 3)的最小和最大时间。CHECKINOUT报告应如下所示 -

USERID      |   DAY        |    INTIME(MINIMUM TIME)     | OUTTIME(MAXIMUM TIME)
=================================================================================
   3        | 10/03/2013   |        8:40:20 AM           |     7:03:32 PM
   3        | 11/03/2013   |        9:04:42 AM           |     7:13:33 PM

如何使用 MS Access(.mdb) 数据库中的 PHP 实现上述查询?我认为可以使用子查询。但是,我找不到任何查询浏览器,例如 HeidiSQL、MySQL 查询浏览器、MySQL 终端或 Navicat for MS Access,我应该在哪里编写和测试我的查询。

4

2 回答 2

2

我对访问不太了解,但一般查询应该是这样的:

SELECT
  date(checktime) Day,
  time(min(checktime)) MinTime,
  time(max(checktime)) MaxTime
FROM t
WHERE userid = 3
GROUP BY Day

我用 MySQL 创建了一个小提琴,但是把它变成 MsAccess 应该很简单。忽略奇怪的日期格式......这是 SQLFiddle 正在改变的东西,但Date()应该Time()只返回日期时间的适当部分,而不是将年份设置为 1970 和那些东西。

于 2013-10-08T04:49:19.673 回答
0

看起来像 anviz db ;)
也许它会对某人有所帮助..
来自 att2003.mdb v_record 请求的 MS Access 请求:

SELECT 
First(V_Record.Userid) AS [USER ID], 
First(V_Record.Name) AS Employer,
DateValue([CheckTime]) AS Date, Min(TimeValue([CheckTime])) AS CheckIN,
Max(TimeValue([CheckTime])) AS CheckOUT, 
Format(Max(TimeValue([CheckTime]))-Min(TimeValue([CheckTime])),"hh:nn") AS [Work Time],
First(V_Record.Sensorid) AS [Device ID], 
First(V_Record.ClientName) AS [Device name]
FROM V_Record
GROUP BY DateValue([V_Record.CheckTime]), V_Record.Userid
ORDER BY DateValue([V_Record.CheckTime]), First(V_Record.Name);
于 2014-10-23T06:36:28.200 回答