下表显示了checkin&员工结账时间
employee_oid report_date report_time
11 2014-12-01 08:02:31
21 2014-12-01 08:13:04
06 2014-12-01 08:13:04
11 2014-12-02 18:03:41
21 2014-12-02 16:36:02
06 2014-12-03 16:36:02
11 2014-12-04 08:02:31
06 2014-12-04 08:36:02
21 2014-12-02 08:36:02
11 2014-12-04 16:34:20
06 2014-12-05 08:36:02
21 2014-12-05 08:50:50
答案 0 :(得分:0)
工作时间算法是什么? 假设工作时间等于结账时间减去签到时间,我得到了这个SQL:
SELECT
Emp_id,
report_date,
MIN(report_time) AS checkin_time,
MAX(report_time) AS checkout_time,
DATE_FORMAT (MAX(report_time) - MIN(report_time), '%h') AS working_hours
FROM
report
GROUP BY Emp_id;
但是,当员工一次又一次地去上班时,这很糟糕......
我徘徊为什么员工应该在第二天结账。当我看到员工06在两天后退房时,这也令人困惑。囧
答案 1 :(得分:0)
对于夜班,我尝试了这个可能有帮助的SQL:
SELECT
a.`id` AS employ_id,
ADDTIME(MIN(a.adjustedDateTime), '12:00:00') AS check_in_time,
ADDTIME(MAX(a.adjustedDateTime), '12:00:00') AS check_out_time,
TIMEDIFF(
MAX(a.adjustedDateTime),
MIN(a.adjustedDateTime)
) AS working_time,
COUNT(0) AS report_times,
DATE_FORMAT(a.adjustedDateTime, '%Y-%m-%d') AS report_date
FROM
(SELECT
`Emp_id` AS id,
SUBTIME(
CONCAT(report_date, ' ', report_time),
'12:00:00'
) AS adjustedDateTime
FROM
report) a
GROUP BY a.`id`,
DATE_FORMAT(a.adjustedDateTime, '%Y-%m-%d')
ORDER BY a.`id`, report_date;
我使用SUBTIME
制作报告时间,在一个班次中收集到一天。然后按日期分组。从而得到了结果。
答案 2 :(得分:0)
<?php
require_once('dbconn.php');
$q="select employee_oid, min(concat(report_date,' ',report_time)) as checkin, max(concat(report_date,' ',report_time)) as checkout from report_master where 1 group by employee_oid,report_date;";
$rec = mysql_query($q);
$k=0;
$i=0;
$previous_empid=0;
if(mysql_num_rows($rec) > 0)
{
$arr=$arr2 = array();
while($row = mysql_fetch_array($rec))
{
$employee_oid = $row['employee_oid'];
$minmumdate = $row['checkin'];
$maxdate = $row['checkout'];
$timestamp1 = strtotime($minmumdate);
$timestamp2 = strtotime($maxdate);
$hour = abs($timestamp2 - $timestamp1)/(60*60);
$arr[$employee_oid][] = array(
'hours'=>$hour
);
}
//print_r($arr);
foreach($arr as $key=>$result){
//echo $key.' key value';
$total_hours=0;
foreach($result as $key1=>$result1){
$total_hours= $total_hours + $result1['hours'];
}
if($total_hours>176) {
$extra_hours = $total_hours - 176;
$extra_wages = $extra_hours * 31.25;
}
$arr2[$key][] = array(
'total_hours'=>$total_hours,
'extra_hours'=>$extra_hours,
'extra_wages' =>$extra_wages
);
}
print("<pre>");
print_r($arr2);
exit();
foreach($arr2 as $key=>$result){
echo $key.' = > total_hours '.$result['total_hours'].' extra_hours '.$result['extra_hours'].' extra_wages '.$result['extra_wages'].'</br></br>';
}
}
?>
答案 3 :(得分:0)
我有这个查询:-
select DATE_FORMAT(yb_date, '%d') AS yb_date,'2' as roll,'asd' AS staff_name,CASE WHEN yb.yb_date> '5050-12-31' THEN '' WHEN yb.yb_date<'0' THEN '' WHEN yb.yb_date> CURDATE() THEN '' WHEN yb.day_status = 'Holiday' AND date(a.attend_date) IS NULL THEN 'H' WHEN date(a.attend_date) IS NULL THEN 'A' ELSE 'P' END AS status,CASE WHEN time(min(attend_date)) IS NULL THEN '00:00:00' ELSE time(min(attend_date)) END as in_time,CASE WHEN time(max(attend_date)) IS NULL THEN '00:00:00' ELSE time(max(attend_date)) END as out_time,CASE WHEN timediff(time(max(attend_date)),time(min(attend_date))) IS NULL THEN '00:00:00' ELSE timediff(time(max(attend_date)),time(min(attend_date))) END as duration from yearbook yb LEFT join attendance_essl a ON date(a.attend_date)=yb.yb_date AND a.emp_id='000012' where yb.yb_date between '2019-09-29' AND '2019-10-05' group by yb.yb_date,a.emp_id order by yb.yb_date ASC
输出为:-
yb_date
roll
staff_name
status
in_time
out_time
duration
29
2
asd
H
00:00:00
00:00:00
00:00:00
30
2
asd
A
00:00:00
00:00:00
00:00:00
01
2
asd
A
00:00:00
00:00:00
00:00:00
02
2
asd
P
17:10:03
17:10:03
00:00:00
03
2
asd
P
15:10:03
15:10:03
00:00:00
04
2
asd
P
06:10:03
18:10:03
12:00:00
05
2
asd
H
00:00:00
00:00:00
00:00:00
如果我加夜班意味着怎么去