热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

比较难的sql面试题,令我比较郁闷!

一组通话记录(总共500万条):ID主叫号码被叫号码通话起始时间  通话结束时间          通话时长1 9829000002154665466562007-02-0109:
一组通话记录(总共500万条):
ID 主叫号码 被叫号码 通话起始时间   通话结束时间           通话时长
1  98290000 0215466546656 2007-02-01 09:49:53.000 2007-02-01 09:50:16.000 23
2  98290000 021546654666  2007-02-01 09:50:29.000 2007-02-01 09:50:41.000 12
3  98290000 021546654666  2007-02-01 09:50:58.000 2007-02-01 09:51:12.000 14
4  68290900 0755133329866 2007-02-01 10:04:31.000 2007-02-01 10:07:13.000 162
5  78290000 0755255708638 2007-02-01 10:48:26.000 2007-02-01 10:49:23.000 57
6  78290000 0755821119109 2007-02-01 10:49:39.000 2007-02-01 10:52:55.000 196
7  78290000 035730928370  2007-02-01 11:30:45.000 2007-02-01 11:31:58.000 73
8  78290000 0871138889904 2007-02-01 11:33:47.000 2007-02-01 11:35:00.000 73
9  68290000 035730928379  2007-02-01 11:52:20.000 2007-02-01 11:54:56.000 156
10 68290000 0298521811199 2007-02-01 12:44:45.000 2007-02-01 12:45:04.000 19
求其中同一个号码的两次通话之间间隔大于10秒的通话记录ID
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


比较难的sql面试题,令我比较郁闷!


推荐阅读
author-avatar
不懂珍惜的林记热_713
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有