SQL 쿼리에서 두 번째로 시간을 변환하도록 도와 주시겠습니까? MySql 함수 SEC_TO_TIME을 사용하고 있습니다.
TIME_FORMAT(SEC_TO_TIME(COALESCE(ROUND(NBSECONDS), 0)),'%H:%i:%s') AS MYTIME
이 함수는 '838 : 59 : 59'로 제한되어 있고 1000 시간 이상이 있기 때문에 대안을 찾아야합니다.
감사합니다
다음과 같이 MySQL에서 자신의 함수를 간단히 작성할 수 있습니다.
drop function if exists my_sec_to_time;
delimiter $$
create function my_sec_to_time(p_sec int)
returns varchar(10)
deterministic
begin
declare v_hour int;
declare v_minute int;
declare v_tmp_sec int;
set v_hour = floor(p_sec / 3600);
set v_tmp_sec = p_sec - (v_hour * 3600);
set v_minute = floor(v_tmp_sec / 60);
set v_tmp_sec = v_tmp_sec - (v_minute * 60);
return concat(v_hour, ':', v_minute, ':', v_tmp_sec);
end $$
delimiter ;
실행 중 :
mysql;root@localhost(playground)> select my_sec_to_time(3020399);
+-------------------------+
| my_sec_to_time(3020399) |
+-------------------------+
| 838:59:59 |
+-------------------------+
1 row in set (0.00 sec)
mysql;root@localhost(playground)> select my_sec_to_time(3020400);
+-------------------------+
| my_sec_to_time(3020400) |
+-------------------------+
| 839:0:0 |
+-------------------------+
1 row in set (0.00 sec)
mysql;root@localhost(playground)> select my_sec_to_time(4020400);
+-------------------------+
| my_sec_to_time(4020400) |
+-------------------------+
| 1116:46:40 |
+-------------------------+
1 row in set (0.00 sec)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다