2
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 

在这种语法中,它只确定员工的先入和后出,但我想问一下我如何计算他/她在第一个进和最后一个出员工之间的时间差或总时间。

例如,员工的先到是上午 9:00:00,最后到是下午 16:00:00。我如何计算该员工的总工作时间?

4

2 回答 2

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;
于 2013-07-15T10:56:37.737 回答
0

通过这个,您可以找到 firstin 和 lastout 之间的小时数差异

SELECT DATEDIFF(小时, firstin(datetime), lastout(datetime)) FROM table_name

于 2013-07-15T10:58:24.530 回答