目前,我正在用SQL执行此操作:
select emp_code,in_time,out_time,worked_time,WT,shift_work_time,
case when enable_overtime = 1 and TIMEDIFF(WT,shift_work_time) > 0
then hour(TIMEDIFF(WT,(shift_work_time))) else 0 end as OT
FROM myTable;
第8行的OT错误,因为shift_work_time是小时格式,所以我想将以小时为单位的shift_worke_time转换为hh:mm:ss,我该怎么做? 预先谢谢你
我也尝试过
TIME_FORMAT(shift_worke_time, '%H:%i:%s')
,但当shift_worke_time为10
时,输出为00:00:10
,但应为
10:00:00
答案 0 :(得分:0)
使用STR_TO_DATE
(shift_worke_time,'%H')
SELECT
select emp_code,in_time,out_time,worked_time,WT,(shift_worke_time,'%H') as shift_worke_time,
case when enable_overtime = 1 and TIMEDIFF(WT,(shift_worke_time,'%H')) > 0
then hour(TIMEDIFF(WT,(shift_worke_time,'%H'))) else 0 end as OT
FROM myTable;