0

使用 SQL Server 2000

例如

表格1

time

01:02
00:02
02:37
02:58
....

时间格式为HH:MM

我想用最接近的值四舍五入时间。喜欢

01 to 04 means 00 only, 05 to 09 means 05 only, 10 to 14 means 10 only..... 55 to 59 means 55 only, 01:00 to 01:04 means 01:00 only....

预期产出

表格1

time

01:00
00:00
02:35
02:55
....

如何查询上述条件。

需要查询帮助

4

2 回答 2

4
select substring([time], 1, 3) + 
       right(rtrim(('0' + cast(substring([time], 4, 2) / 5 * 5 as CHAR))), 2)
from table1
于 2012-06-06T10:13:15.740 回答
1
SELECT
  CONVERT(
    char(5),
    DATEADD(MINUTE, DATEDIFF(MINUTE, 0, time) / 5 * 5, 0),
    108
  ) AS time
FROM Table1
于 2012-06-07T07:58:40.797 回答