MySQL查询考勤进/出计算

时间:2018-06-21 04:03:04

标签: mysql

DROP TABLE IF EXISTS Attendances;
CREATE TABLE Attendances (id int, employee_id int, timedata datetime, in_out varchar(55));
INSERT INTO Attendances (id, employee_id, timedata, in_out) VALUES 
        (1, 1,'2017-06-07 19:25:10','OUT'),
        (2, 1,'2017-06-08 09:25:17','IN'),
        (3, 1,'2017-06-08 13:51:02','IN'),
        (4, 1,'2017-06-08 20:44:14','OUT'),
        (5, 1,'2017-06-09 01:10:04','OUT'),
        (6, 1,'2017-06-09 14:11:40','IN'),
        (7, 1,'2017-06-09 19:41:26','OUT'),
        (8, 1,'2017-06-09 11:35:00','IN'),
        (9, 1,'2017-06-09 20:36:06','OUT');

我的数据:

id  employee_id        timedata       in_out
 1       1       07.06.2017 19:25:10    OUT
 2       1       08.06.2017 09:25:17    IN
 3       1       08.06.2017 13:51:02    IN
 4       1       08.06.2017 20:44:14    OUT
 5       1       09.06.2017 01:10:04    OUT
 6       1       09.06.2017 14:11:40    IN
 7       1       09.06.2017 19:41:26    OUT
 8       1       09.06.2017 11:35:00    IN
 9       1       09.06.2017 20:36:06    OUT

我想将数据传输到带有结果的MySQL查询中:

employee_id      time_in                time_out
    1              NULL             07.06.2017 19:25:10
    1        08.06.2017 09:25:17           NULL
    1        08.06.2017 13:51:02    08.06.2017 20:44:14
    1              NULL             09.06.2017 01:10:04
    1        09.06.2017 14:11:40    09.06.2017 19:41:26
    1        09.06.2017 11:35:00    09.06.2017 20:36:06

请帮助我。 任何建议表示赞赏。

0 个答案:

没有答案