gpt4 book ai didi

mysql - 将小时格式转换为 hh :mm:format in MySql

转载 作者:行者123 更新时间:2023-11-29 17:13:58 24 4
gpt4 key购买 nike

目前我正在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com