SELECT empno , date_created ,
min(CASE WHEN status = 0 THEN time_created END) time_in,
max(CASE WHEN status = 1 THEN time_created END) time_out
FROM biometrics
WHERE empno = 3
GROUP BY empno , date_created
在此语法中,它仅确定员工的第一个和最后一个但是 我想问一下如何计算他/她在员工的第一个IN和最后一个之间的时差或总时间。
例如员工的第一个上午9:00:00,最后一个下午是16:00:00。如何计算该员工的总工时?
答案 0 :(得分:1)
请尝试以下方法:
select
empno,
date_created,
time_in,
time_out,
time_format(timediff(time_out, time_in), '%H:%i') as total_time
from
(
SELECT empno, date_created,
min(CASE WHEN status = 0 THEN time_created END) time_in,
max(CASE WHEN status = 1 THEN time_created END) time_out
FROM biometrics
WHERE empno = 3
GROUP BY empno, date_created
) t1;
答案 1 :(得分:0)
通过这个你可以找到firstin和lastout之间的小时差异
SELECT DATEDIFF(hour, firstin(datetime), lastout(datetime)) FROM table_name