如何计算HH MM SS格式的总时间

时间:2012-11-09 04:52:29

标签: sql-server time-format

有一个表格为每个用户提供HH MM SS格式的用法详细信息,如何计算HH MM SS格式的总使用量

enter image description here


i want result to be total=6:47:33
我知道这是非常基本但无法弄清楚

2 个答案:

答案 0 :(得分:2)

你总是可以用老式的方式来做:

;WITH s AS (SELECT SUM(((Hours * 60) + Minutes) * 60 + Seconds) AS t FROM myTable)
SELECT CAST(t / 60 / 60 AS VARCHAR(10)) + ':' + RIGHT('0' + CAST((t / 60) % 60 AS VARCHAR(2)),2) + ':' + RIGHT('0' + CAST(t % 60 AS VARCHAR(2)), 2) AS total
FROM s

SQL Fiddle example

答案 1 :(得分:0)

;with cte as (select (hours * (60*60))+(minutes * 60)+seconds as seconds from table)

select cast(sum(case when seconds = 0 then 0 else 1. / (86400. / seconds) end) as datetime)
from cte