我如何在MySQL中舍入到最近的60秒间隔

时间:2012-08-21 19:45:14

标签: mysql time numbers rounding

我有一张有电话记录的表。详细信息的phone_number和call_time在毫秒中。哪个SQL语句的舍入call_time为最接近的前60位秒?例如:

phone_number | call_time | rounded_time
=====================================
787-468-8965 |  45786    |   60
787-564-8945 | 128907    |   180

谢谢

1 个答案:

答案 0 :(得分:4)

  • 转换为分钟。
  • 使用CEILING功能整理到下一分钟。
  • 转换回秒。

试试这个:

CREATE VIEW yourview AS
SELECT
    CEILING(call_time / 60000) * 60,
    -- etc...