- --题5)创建一张表,记录电话呼叫员的工作流水,记录呼叫员编号,对方号码,通话开始时间,通话结束时间,。
- --创建一张表T_Callers,记录电话呼叫员的工作流水,记录呼叫员编号、对方号码、通话开始时间、通话结束时间。建表、插数据等最后都自己写SQL语句。
- --要求:
- --1)输出所有数据中通话时间最长的5条记录。
- --2)输出所有数据中拨打长途号码对方号码以0开头)的总时长。
- --3)输出本月通话总时长最多的前三个呼叫员的编号。
- --4)输出本月拨打电话次数最多的前三个呼叫员的编号。
- --5)输出所有数据的拨号流水,并且在最后一行添加总呼叫时长。
- --记录呼叫员编号、对方号码、通话时长
- --......
- --汇总[市内号码总时长][长途号码总时长]
- --IdCallerNumberTellNumberStartDateTimeEndDateTime
- --1001020888888882010-7-1010:012010-7-1010:05
- --2001020888888882010-7-1113:412010-7-1113:52
- --3001898989892010-7-1114:422010-7-1114:49
- --4002021883689812010-7-1321:042010-7-1321:18
- --5002767676762010-6-2920:152010-6-2920:30
- --6001022888782432010-7-1513:402010-7-1513:56
- --7003672546862010-7-1311:062010-7-1311:19
- --8003862314452010-6-1919:192010-6-1919:25
- --9001874223682010-6-1919:252010-6-1919:36
- --10004400458622452010-6-1919:502010-6-1919:59
- --创建表
- createtableT_CallRecords(
- idintnotnull,
- CallerNumbervarchar(3),
- TellNumbervarchar(13),
- StartDateTImedatetime,
- EndDateTimedatetime,
- Primarykey(Id)
- );
- --插入数据
- insertintoT_CallRecords(Id,CallerNumber,TellNumber,StartDateTime,EndDateTIme)
- values(1,'001','02088888888','2010-7-1010:01','2010-7-1010:05');
- INSERTINTOT_CallRecords(Id,CallerNumber,TellNumber,StartDateTime,EndDateTime)
- VALUES(2,'002','02088888888','2010-7-1113:41','2010-7-1113:52');
- INSERTINTOT_CallRecords(Id,CallerNumber,TellNumber,StartDateTime,EndDateTime)
- VALUES(3,'003','89898989','2010-7-1114:42','2010-7-1114:49');
- INSERTINTOT_CallRecords(Id,CallerNumber,TellNumber,StartDateTime,EndDateTime)
- VALUES(4,'004','02188368981','2010-7-1321:04','2010-7-1321:18');
- INSERTINTOT_CallRecords(Id,CallerNumber,TellNumber,StartDateTime,EndDateTime)
- VALUES(5,'005','76767676','2010-6-2920:15','2010-6-2920:30');
- INSERTINTOT_CallRecords(Id,CallerNumber,TellNumber,StartDateTime,EndDateTime)
- VALUES(6,'006','02288878243','2010-7-1513:40','2010-7-1513:56');
- INSERTINTOT_CallRecords(Id,CallerNumber,TellNumber,StartDateTime,EndDateTime)
- VALUES(7,'007','67254686','2010-7-1311:06','2010-7-1311:19');
- INSERTINTOT_CallRecords(Id,CallerNumber,TellNumber,StartDateTime,EndDateTime)
- VALUES(8,'008','86231445','2010-6-1919:19','2010-6-1919:25');
- INSERTINTOT_CallRecords(Id,CallerNumber,TellNumber,StartDateTime,EndDateTime)
- VALUES(9,'009','87422368','2010-6-1919:25','2010-6-1919:36');
- INSERTINTOT_CallRecords(Id,CallerNumber,TellNumber,StartDateTime,EndDateTime)
- VALUES(10,'010','40045862245','2010-6-1919:50','2010-6-1919:59');
- --修改呼叫员编号
- UPDATET_CallRecordsSETCallerNumber='001'WHEREIdIN(1,2,3,6,9);
- UPDATET_CallRecordsSETCallerNumber='002'WHEREIdIN(4,5);
- UPDATET_CallRecordsSETCallerNumber='003'WHEREIdIN(7,8);
- UPDATET_CallRecordsSETCallerNumber='004'WHEREId=10;
- --数据汇总
- select*fromT_CallRecords
- --题1):输出所有数据中通话时间最长的5条记录。
- --@计算通话时间;
- --@按通话时间降序排列;
- --@取前5条记录。
- selecttop5CallerNumber,DATEDIFF(SECOND,StartDateTime,EndDateTime)as总时长
- fromT_CallRecords
- orderbyDATEDIFF(SECOND,StartDateTime,EndDateTime)DESC
- --题2):输出所有数据中拨打长途号码对方号码以0开头)的总时长
- --@查询拨打长途号码的记录;
- --@计算各拨打长途号码的通话时长;
- --@对各拨打长途号码的通话时长进行求和。
- selectSUM(DATEDIFF(SECOND,StartDateTime,EndDateTime))as总时长fromT_CallRecords
- whereTellNumberlike'0%'
- --题3):输出本月通话总时长最多的前三个呼叫员的编号。
- --@按呼叫员编号进行分组;
- --@计算各呼叫员通话总时长;
- --@按通话总时长进行降序排列;
- --@查询前3条记录中呼叫员的编号。
- selectdatediff(month,convert(datetime,'2010-06-01'),convert(datetime,'2010-07-22'))--测试
- selectCallerNumber,TellNumber,datediff(month,StartDateTime,EndDateTime)
- fromT_CallRecords
- selecttop3CallerNumberfromT_CallRecords
- wheredatediff(month,StartDateTime,getdate())=12--一年前的
- groupbyCallerNumber
- orderbySUM(DATEDIFF(SECOND,StartDateTime,EndDateTime))DESC
本站文章为和通数据库网友分享或者投稿,欢迎任何形式的转载,但请务必注明出处.
同时文章内容如有侵犯了您的权益,请联系QQ:970679559,我们会在尽快处理。