目前我正在 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
最佳答案
使用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;
关于mysql - 将小时格式转换为 hh :mm:format in MySql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51740115/