我需要使用 Sql Server 2008 对小时、分钟和秒求和
该字段仅包含时间值。
输入
ID HORA_S
-- ----------------------
1 1899-12-30 18:22:50.000
2 1899-12-30 18:22:50.000
3 1899-12-30 18:30:50.000
输出
HOURS MINUTES SECONDS
---- --- --------
55 16 30
在玩弄了这段代码之后,我解决了!!!
SELECT SUM(DATEPART(hh, CAST(HORA_S AS DATETIME)))
+ ( SUM(DATEPART(MINUTE, CAST(HORA_S AS DATETIME))) / 60 )
+ ( SUM(DATEPART(MINUTE, CAST(HORA_S AS DATETIME))) % 60
+ ( SUM(DATEPART(SECOND, CAST(HORA_S AS DATETIME))) / 60 ) ) / 60 AS HORAS,
( SUM(DATEPART(MINUTE, CAST(HORA_S AS DATETIME))) % 60
+ ( SUM(DATEPART(SECOND, CAST(HORA_S AS DATETIME))) / 60 ) ) % 60 AS MINUTOS,
SUM(DATEPART(SECOND, CAST(HORA_S AS DATETIME))) % 60 AS SEGUNDOS FROM Table