电话通话次数以及时长
--电话通话次数以及时长
DECLARE @T TABLE (id INT,号码 INT,通话时长 VARCHAR(8))
INSERT INTO @T
SELECT 1,21981052,'00:01:19' UNION ALL
SELECT 2,21981052,'00:00:26' UNION ALL
SELECT 3,21980021,'00:00:56' UNION ALL
SELECT 4,21980389,'00:02:05' UNION ALL
SELECT 5,21980389,'00:00:41' UNION ALL
SELECT 6,21981056,'00:00:31' UNION ALL
SELECT 7,21981056,'00:00:13'
SELECT 号码,COUNT(*) AS 通话次数,
convert(varchar(8),dateadd(ss,SUM(DATEDIFF(ss,0,通话时长)),0),108) 通话时长
FROM @T
GROUP BY 号码
ORDER BY 号码
/*
号码 通话次数 通话时长
----------- ----------- --------
21980021 1 00:00:56
21980389 2 00:02:46
21981052 2 00:01:45
21981056 2 00:00:44
(所影响的行数为 4 行)
*/
--ss 秒
/*
select CONVERT(varchar(12) , getdate(), 108 )
11:06:08
*/
DECLARE @T TABLE (id INT,号码 INT,通话时长 VARCHAR(8))
INSERT INTO @T
SELECT 1,21981052,'00:01:19' UNION ALL
SELECT 2,21981052,'00:00:26' UNION ALL
SELECT 3,21980021,'00:00:56' UNION ALL
SELECT 4,21980389,'00:02:05' UNION ALL
SELECT 5,21980389,'00:00:41' UNION ALL
SELECT 6,21981056,'00:00:31' UNION ALL
SELECT 7,21981056,'00:00:13'
SELECT 号码,COUNT(*) AS 通话次数,
convert(varchar(8),dateadd(ss,SUM(DATEDIFF(ss,0,通话时长)),0),108) 通话时长
FROM @T
GROUP BY 号码
ORDER BY 号码
/*
号码 通话次数 通话时长
----------- ----------- --------
21980021 1 00:00:56
21980389 2 00:02:46
21981052 2 00:01:45
21981056 2 00:00:44
(所影响的行数为 4 行)
*/
--ss 秒
/*
select CONVERT(varchar(12) , getdate(), 108 )
11:06:08
*/