我正在尝试实现返回" best"三次。我的数据库字段是:
FIRST_TIME - this is a long value in milliseconds from the epoch
SECOND_TIME - also a long value in milliseconds from the epoch
THIRD_TIME - this is an Time field, representing US/Eastern time, like 08:30:52
我的逻辑应该是:
我可以使用FROM_UNIXTIME来获取HH中的前两个字段:mm:ss,但我对如何将其转换为正确的时区感到困惑,而且如何比较我的字段并返回最佳值。
答案 0 :(得分:0)
很好,谢谢Marc!现在我可以使用以下方法将我的纪元时间转换为时间值:
TIME(CONVERT_TZ(FROM_UNIXTIME(SUBSTRING(FIRST_TIME,1,10)),'GMT','US/Eastern'))
现在剩下的就是如何使用MySQL来为我理清逻辑。我能够做到这一点:
(IF (FIRST_TIME IS NOT NULL,
TIME(CONVERT_TZ(FROM_UNIXTIME(SUBSTRING(FIRST_TIME,1,10)),'GMT','US/Eastern')),
IF(TIME(CONVERT_TZ(FROM_UNIXTIME(SUBSTRING(SECONT_TIME,1,10)),'GMT','US/Eastern')) > THIRD_TIME,
TIME(CONVERT_TZ(FROM_UNIXTIME(SUBSTRING(SECOND_TIME,1,10)),'GMT','US/Eastern')),
THIRD_TIME))
) AS BEST_TIME,