Ms时间处理收集
Sum聚合函数对DateTime数据类型字段进行求和统计
求同一时间字段时间总和
declare @t table(TimeLen char(8))
insert into @t select '08:32:33'
insert into @t select '00:00:06'
insert into @t select '00:00:30'
insert into @t select '00:00:13'
insert into @t select '00:00:15'
insert into @t select '00:00:08'
insert into @t select '00:00:54'
insert into @t select '00:00:48'
insert into @t select '00:00:33'
select convert(char(8),dateadd(ss,sum(datediff(ss,0,cast(TimeLen as datetime))),0),108) As TimeSum from @t
大概思路就是
1.用Cast函数将@TimeLen字段的Char类型专换为DateTime类型
2.用DateDiff函数转换为integer类型的秒数
3.用Sum函数求总和
4.用DateAdd函数再转换为yyyy-mm-dd hh:mi:ss:mmm格式
5.用Convert函数最后再转换为原来的hh:mm:ss格式