I'd like the sum of TotalVisitedTime time but it is alias column so how can I gtt it?
Select CONVERT(varchar(6), DATEDIFF(second, [Start], [End])/3600)
+ ':'
+ RIGHT('0' + CONVERT(varchar(2), (DATEDIFF(second, [Start], [End])开发者_JS百科 % 3600) / 60), 2)
+ ':'
+ RIGHT('0' + CONVERT(varchar(2), DATEDIFF(second, [Start], [End]) % 60), 2) AS TotalVisitedTime
FROM [Table Name]
Note: [Start] and [End] are columns name.
SELECT SUM(TotalVisitedTime)
FROM (
-- AS PER @Alex Aza, @Andriy M
SELECT 1234 AS TotalVisitedTime
) AS OuterTable
I think it makes sense to sum up seconds and then do the conversion you are trying to do.
SELECT CONVERT(varchar(6), diff/3600)
+ ':'
+ RIGHT('0' + CONVERT(varchar(2), (diff % 3600) / 60), 2)
+ ':'
+ RIGHT('0' + CONVERT(varchar(2), diff % 60), 2) AS TotalVisitedTime
FROM
(
select sum(DATEDIFF(second, [Start], [End]) diff
from [Table Name]
) tt
精彩评论