log_date log_time emp_id emp_name log_action
2013-06-16 08:48:48.0000000 30170 Sarah John 1
2013-06-16 16:48:48.0000000 30170 Sarah John 4
2013-06-15 07:18:48.0000000 30160 Paula Fred 1
2013-06-15 16:38:48.0000000 30160 Paula Fred 4
我有一个包含上述信息的日志表。我有一个查询来计算每个员工的每日工作时间并将它们存储在另一个的十进制字段中。问题是分钟已关闭,如果员工在同一天多次打卡/打卡,则会增加小时数。我希望它只考虑第一个好的打孔/打孔。
Select DISTINCT emp_id,log_date,SUM(datediff(Minute,stm, etm))/60.0
as wrk_hrs from
(
SELECT
emp_id, log_date,
log_time as etm,
(
SELECT top 1 log_time
FROM tblLogs
WHERE log_action = '1' and log_time <= a.log_time and emp_id=a.emp_id and a.log_date=log_date order by log_time desc
) as stm
FROM tblLogs as a
WHERE log_action = '4'
)as a
where stm is not null
group by log_date,emp_id,a.stm,a.etm;
是否有更准确的方法来计算小时和分钟并存储它们以供进一步计算。我需要一段时间和每周的总小时数来生成报告。