CREATE TABLE 通话(id int ,主叫号码 varchar(8),被叫号码 varchar(30),通话起始时间 datetime ,通话结束时间 datetime,通话时长 int)
INSERT INTO 通话
select 1 , '98290000','0215466546656','2007-02-01 09:49:53.000', '2007-02-01 09:50:16.000',23 union
select 2, '98290000' ,'021546654666' ,'2007-02-01 09:50:29.000', '2007-02-01 09:50:41.000', 12 union
select 3, '98290000', '021546654666 ' ,'2007-02-01 09:50:58.000' ,'2007-02-01 09:51:12.000', 14 union
select 4, '68290900' ,'0755133329866', '2007-02-01 10:04:31.000', '2007-02-01 10:07:13.000' ,162 union
select 5, '78290000' ,'0755255708638' ,'2007-02-01 10:48:26.000', '2007-02-01 10:49:23.000', 57 union
select 6, '78290000' ,'0755821119109', '2007-02-01 10:49:39.000' ,'2007-02-01 10:52:55.000' ,196 union
select 7, '78290000', '035730928370' , '2007-02-01 11:30:45.000', '2007-02-01 11:31:58.000', 73 union
select 8, '78290000', '0871138889904', '2007-02-01 11:33:47.000', '2007-02-01 11:35:00.000' ,73 union
select 9, '68290000' ,'035730928379' ,'2007-02-01 11:52:20.000', '2007-02-01 11:54:56.000' ,156 union
select 10 ,'68290000','0298521811199', '2007-02-01 12:44:45.000', '2007-02-01 12:45:04.000' ,19
SELECT a.id
from 通话 a, 通话 b
where a.主叫号码=b.主叫号码
and a.id!=b.id
and datediff(s,b.通话起始时间,a.通话起始时间)>10
UNION
SELECT b.id
from 通话 a, 通话 b
where a.主叫号码=b.主叫号码
and a.id!=b.id
and datediff(s,a.通话起始时间,b.通话起始时间)>10