Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
I need to sum seconds in a column and divide by another column, and report the average in hours, minutes & seconds. I know how to report the sum of the seconds, and how to report the seconds column in hours, minutes & seconds, but don't know how to combine SUM & CONVERT.Thanks for any help!
Lamprey
Master Smack Fu Yak Hacker
4614 Posts
Posted - 2012-04-20 : 17:57:47
Maybe this wil help:
DECLARE @T TABLE (ID INT, Val INT)INSERT @TVALUES(1, 5),(1, 12),(1, 7),(1, 18),(1, 3),(1, 45),(1, 50),(2, 75),(2, 135),(2, 9),(2, 19),(2, 46),(2, 15),(2, 20)SELECT ID, CAST(DATEADD(SECOND, SUM(Val), '19000101') AS TIME)FROM @TGROUP BY ID