SQL如何在SQL查询中将表中的毫秒数转换为HH:MM:SS?

问题描述 投票:0回答:1

PHP版本:使用phpMyAdmin的7.3.6

我已经看到了一些与此相关的帖子,但是我一直在努力寻找适合我的答案。我正在尝试将竞赛结果时间显示在表中的HH:MM:SS中,以毫秒为单位

SELECT
MIN(Result.Time) AS MinTime, event_cat_id

FROM
Wp_wpa_result Result
INNER JOIN Wp_wpa_event Race ON Result.Event_id = Race.Id 
WHERE Race.Sub_type_id = 'R' AND Age_grade <> 'null' AND event_cat_id IN ( '30', '11', '12', '13', '14', '17', '20', '19', '15'  )
GROUP BY event_cat_id
)


SELECT  U.Display_name, EVC.Name AS EventDistance, EV.name AS RaceName, MinTime,  EV.Date, RE.Age_Grade AS AgeGrade, EV.Sub_type_id AS Terrain, EV.Date AS RaceDate
FROM CTE

INNER JOIN Wp_wpa_event_cat EVC ON EVC.id = CTE.event_cat_id  
INNER JOIN Wp_wpa_event EV ON EV.Event_cat_id = CTE.event_cat_id 
INNER JOIN Wp_wpa_result RE ON EV.id = RE.event_id AND CTE.MinTime = RE.Time
INNER JOIN wp_users U ON U.ID = RE.user_id
ORDER BY MinTime;

显示名称|| EventDistance ||种族|| MinTime ||日期|| AgeGrade ||地形|| RaceDate

Dave博客|| 5k Worden Place 5k || 1042000 || 2019年6月4日|| 74.76 || R || 2019年6月4日

但应该是

Dave博客|| 5k Worden Place 5k || 00:17:14 || 2019年6月4日|| 74.76 || R || 2019年6月4日

谢谢,亚当

mysql time-format
1个回答
1
投票

您需要功能sec_to_time()

sec_to_time()

如果您希望结果格式为sec_to_time(MinTime / 1000) ,请同时使用hh:mm:ss

time_format()
© www.soinside.com 2019 - 2024. All rights reserved.