查询考勤系统的指纹日志几乎没有问题。
我们的示例数据如下所示:
TABLE FINGER_LOGS:
+++++++++++++++++++++++++++++++++++
| ID | FINGER_ID | DATETIME |
+++++++++++++++++++++++++++++++++++
| 1 | IT | 2015-12-01 09:00
| 2 | IT | 2015-12-01 16:30
| 3 | GA | 2015-12-01 09:30
| 4 | GA | 2015-12-01 17:00
| 5 | SECURITY | 2015-12-01 08:00
| 6 | SECURITY | 2015-12-01 19:00
| 7 | SECURITY2 | 2015-12-01 19:00
| 8 | SECURITy2 | 2015-12-02 07:00
我们必须将TABLE FINGER_LOGS的格式更改为:
++++++++++++++++++++++++++++++++++++++++
| FINGER_ID | DATE | IN | OUT |
++++++++++++++++++++++++++++++++++++++++
| IT | 2015-12-01 | 09:00 | 16:30
| GA | 2015-12-01 | 09:00 | 17:00
| SECURITY | 2015-12-01 | 08:00 | 19:00
| SECURITy2 | 2015-12-01 | 19:00 | 07:00
| SECURITy2 | 2015-12-02 | 19:00 | 07:00
我们尝试过这个查询:
SELECT
i.FINGER_ID, i.DATE, i.TIME_IN, o.TIME_OUT
FROM
(SELECT
i.FINGER_ID,
min(cast(i.DATE as date)) as 'DATE',
DATE(DATE_ADD(i.DATE, INTERVAL + 1 DAY)) as 'TOMMOROW',
min(cast(i.DATE as time)) as 'TIME_IN'
FROM
FINGER_LOGS as i
GROUP BY i.FINGER_ID , cast(i.DATE as date)) as i
LEFT JOIN
(SELECT
o.FINGER_ID,
max(cast(o.DATE as date)) as 'DATE',
max(cast(o.DATE as time)) as 'TIME_OUT'
FROM
FINGER_LOGS as o
GROUP BY o.FINGER_ID , cast(o.DATE as date), DATE(DATE_ADD(o.DATE, INTERVAL - 1 DAY))
) as o ON i.FINGER_ID = o.FINGER_ID
AND (i.DATE = o.DATE
OR o.DATE = i.TOMMOROW)
但结果是:
++++++++++++++++++++++++++++++++++++++++
| FINGER_ID | DATE | IN | OUT |
++++++++++++++++++++++++++++++++++++++++
| IT | 2015-12-01 | 09:00 | 16:30
| GA | 2015-12-01 | 09:00 | 17:00
| SECURITY | 2015-12-01 | 08:00 | 19:00
| SECURITy2 | 2015-12-01 | 19:00 | 19:00
| SECURITy2 | 2015-12-01 | 19:00 | 07:00
| SECURITy2 | 2015-12-02 | 07:00 | 07:00
问题的根源在DATE IN&在SECURITy2之外,其具有不同的DATE(从DATE IN开始+1天)
如果您有解决此问题的方法,请告诉我们,
感谢您的帮助和帮助:)
这是来自供应商的必需格式,我来自电子邮件:
....
Our Format :
Database Server = MySQL
DBName = ixfinger
Tablename = fingerlog
Fields :
Finger_id autoincrement_primarkey
fingerid varchar(252) ID from fingerprint
tdate date
timein time
timeout time
transferred tinyint (fill with 0)
....