1

我在 MS Access 2007 中查询 sql。我想用 datetime 找到 mix 和 max 函数。

此代码:

SELECT inf.SSN AS EmpNo, ck.CHECKTIME AS CHKDATE,Min(ck.CHECKTIME) AS TIMEIN, Max(ck.CHECKTIME) AS TIMEOUT
FROM CHECKINOUT ck INNER JOIN USERINFO inf ON ck.Badgenumber = inf.Badgenumber
WHERE (((ck.CHECKTIME)>=#20/03/2013#)
Group By inf.SSN, ck.CHECKTIME
ORDER BY inf.SSN, ck.CHECKTIME

结果:

EmpNo   |     CHKDATE    |  TIMEIN             | TIMEOUT
1290005 | 20/3/2556 7:24:52  |  20/3/2556 7:24:52  | 20/3/2556 7:24:52
1290005 | 20/3/2556 19:07:54 |  20/3/2556 19:07:54 | 20/3/2556 19:07:54
1290005 | 21/3/2556 7:14:29  |  21/3/2556 7:14:29  | 21/3/2556 7:14:29
1320004 | 20/3/2556 7:28:57  |  20/3/2556 7:28:57  | 20/3/2556 7:28:57
1320004 | 20/3/2556 17:05:23 |  20/3/2556 17:05:23 | 20/3/2556 17:05:23
1320004 | 21/3/2556 7:15:30  |  21/3/2556 7:15:30  | 21/3/2556 7:15:30

但我想要结果:

EmpNo   |     CHKDATE    |  TIMEIN             | TIMEOUT
1290005 | 20/3/2556 00:00:00 |  20/3/2556 7:24:52  | 20/3/2556 19:07:54
1290005 | 21/3/2556 00:00:00 |  21/3/2556 7:14:29  | 21/3/2556 7:14:29
1320004 | 20/3/2556 00:00:00 |  20/3/2556 7:28:57  | 20/3/2556 17:05:23
1320004 | 21/3/2556 00:00:00 |  21/3/2556 7:15:30  | 21/3/2556 7:15:30

如何在 Access 2007 中查询此结果。感谢您的宝贵时间。;)

4

2 回答 2

0

我想你想按 EmpNo 和 ChkDate 分组

于 2013-04-23T14:49:26.977 回答
0

Access SQL supports a DateValue() function which returns the date portion of a Date/Time value. (Actually it gives you midnight for that date.) I think it should be useful for what you want.

SELECT
    inf.SSN AS EmpNo,
    DateValue(ck.CHECKTIME) AS CHKDATE,
    Min(ck.CHECKTIME) AS TIMEIN,
    Max(ck.CHECKTIME) AS TIMEOUT
FROM
    CHECKINOUT ck
    INNER JOIN USERINFO inf
    ON ck.Badgenumber = inf.Badgenumber
WHERE ck.CHECKTIME>=#2013/03/20#
GROUP BY inf.SSN, DateValue(ck.CHECKTIME)
ORDER BY 1, 2;
于 2013-04-23T15:16:50.810 回答