我有一个 sql 代码,可以获取每个员工的总工作时间和他的超时时间。我想计算他当天工作的总加班时间。你能帮我解决这个问题吗?8小时是每天的正常时间。
这是代码
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;
样本输出
empno| date_created | time_in | time_out
2 2013-07-15 11:08:07 15:00:00
3 2013-07-15 11:50:00 NULL
4 2013-07-15 NULL 16:00:00
我想要的是这样的
empno | date_created | time_in | time_out | overtime
2 2013-07-15 5:00:00 15:00:00 2