我正在尝试在SQL Server中添加重复行的值。这就是数据的外观
SESSION ID |TALK TIME|TSEC|TMIN |
------------+---------+----+-----+
34000018959 |00:34.0 |34 |0.56 |
34000018959 |20:29.0 |1229|20.48|
这是我用来添加整数
的查询SELECT
[SESSION ID],
SUM([TALK TIME]) AS [TALK TIME],
SUM([TSEC]) AS [TSEC],
SUM([TMIN]) AS [TMIN]
FROM
[TABLE1]
GROUP BY
[SESSION ID], [TALK TIME]
没有使用这个我能够总结TSEC
和TMIN
我想要的。但无法获得SUM
的{{1}}。
这是我希望看到的输出:
Talk Time
答案 0 :(得分:3)
一种简单的方法是将秒数相加并得出其余部分
示例强>
Declare @T table ([SESSION ID] varchar(50),[TALK TIME] varchar(50),tSec int,tmin decimal(10,2))
Insert Into @T values
('34000018959','00:34.0',34,0.56),
('34000018959','20:29.0',1229,20.48)
Select [Session ID]
,[Talk Time] = format(dateadd(SECOND,sum(tSec),0),'mm:ss.f')
,TSec = sum(tSec)
,TMin = cast(sum(tSec+0.0)/60 as decimal(10,2))
From @T
Group By [Session ID]
<强>返回强>
Session ID Talk Time TSec TMin
34000018959 21:03.0 1263 21.05