弹性考勤记录查询SQL中如何处理跨天记录?

弹性考勤记录查询sql

  SELECT
      employee_id,
      punch_in_time,
      punch_out_time,
      CASE
          WHEN punch_out_time < punch_in_time THEN '跨天记录'
          ELSE '正常记录'
      END AS record_type,
      -- 计算工作时长
      CASE
          WHEN punch_out_time < punch_in_time THEN
              TIMESTAMPDIFF(SECOND, punch_in_time, DATE(punch_in_time) + INTERVAL 1 DAY) +
              TIMESTAMPDIFF(SECOND, DATE(punch_out_time), punch_out_time)
          ELSE
              TIMESTAMPDIFF(SECOND, punch_in_time, punch_out_time)
      END AS duration_seconds
  FROM
      attendance_records;

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

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

相关推荐