01.
select
02.
tb1.em_id, tb1.stamp_check st, tb2.stamp_check en,
03.
((@st:=unix_timestamp(tb2.stamp_check)) - (@en:=unix_timestamp(tb1.stamp_check))) timework,
04.
(@late:=(@st - (@fixin:=unix_timestamp(concat(curdate(),
' 08:00'
)))))
as
latein,
05.
((@fixout:=unix_timestamp(concat(curdate(),
' 17:00'
))))
as
beforeout,
06.
(@en - @fixout - if(@late>0, @late, 0))
as
overtime
07.
from
table
as
tb1,
table
as
tb2
08.
where
tb1.em_id=tb2.em_id
09.
and
date
(tb1.stamp_check) =
date
(tb2.stamp_check)
10.
and
tb1.
action
=
'in'
and
tb2.
action
=
'out'
11.
and
date
(tb1.stamp_check)=curdate()