弹性考勤记录查询SQL如何计算员工的实际工作时长?

弹性考勤记录查询sql

SELECT
employee_id,
date,
SUM(
CASE
WHEN check_out_time < check_in_time THEN — 跨天情况
TIMESTAMPDIFF(SECOND,
CASE WHEN check_in_time < ’10:00:00′ THEN ’10:00:00′ ELSE check_in_time END,
’23:59:59′
) + TIMESTAMPDIFF(SECOND, ’00:00:00′,
CASE WHEN check_out_time > ’16:00:00′ THEN ’16:00:00′ ELSE check_out_time END
)
/ 3600
WHEN check_out_time >= check_in_time THEN — 非跨天情况
TIMESTAMPDIFF(SECOND,
CASE WHEN check_in_time < ’10:00:00′ THEN ’10:00:00′ ELSE check_in_time END,
CASE WHEN check_out_time > ’16:00:00′ THEN ’16:00:00′ ELSE check_out_time END
) / 3600
ELSE 0
END
) AS work_hours
FROM
attendance_records
WHERE
date BETWEEN ‘2023-01-01’ AND ‘2023-01-31’ AND employee_id = 123
GROUP BY
employee_id,
date;

利唐i人事HR社区,发布者:ihreditor,转转请注明出处:https://www.ihr360.com/hrnews/20241224226.html

(0)
上一篇 12小时前
下一篇 12小时前

相关推荐