2004-10-25 17:27
seven
<span style='color:red'>1. 准备:</span><br />1.1 短信清单,可以到移动网站查自己的短信话单,cp下来,利用editplus的纵列选择功能把短信号码那一栏取出来,保存为sms_details<br />1.2 建表:<br />1.2.1 短信清单表:<br />create table sms_details(sms_details varchar(11));<br />1.2.2 手机号码与姓名对应表<br />create table sms2name(phone varchar(11) not null primary key, name varchar(8));<br /><br /><span style='color:red'>2. 脚本</span><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><br />#!/usr/bin/ksh<br />db2 "connect to db_name" > /dev/null 2>&1; #连接数据库 db_name为具体数据库名<br /><br />I=0 &nbsp;#记录短信清单条数<br />J=0 &nbsp;#记录成功插入数据库清单条数<br />K=0 &nbsp;#记录插入失败记录条数<br /><br />echo "请输入短信清单:\c"<br />read SMS_DETAILS<br />while read PHONE<br />do<br /> I=`expr $I + 1`<br /> db2 "insert into sms_details values('$PHONE')" > /dev/null 2>&1; #插库<br /> if [ $? -eq 0 ];then<br /> J=`expr $J + 1`<br /> else<br /> K=`expr $K + 1`<br /> fi<br />done < $SMS_DETAILS<br /><br />echo "共检索出 $I 条数据, 成功插入 $J 条数据, 插入失败 $K 条数据\n"<br /><br />#开始分析数据,生成报表<br />#使用到的高级SQL: CASE表达式, 左外连接<br />db2 -z report "select sms_details as phone, case when a.sms_details=b.phone then b.name else concat ('unknow_', sms_details) end as name, count(a.sms_details) as count from sms_details a left outer join sms2id b on a.sms_details=b.phone group by a.sms_details, b.phone, b.name" > /dev/null 2>&1;<br /><br />#删除短信清单<br />db2 "delete from sms" > /dev/null 2>&1;<br /><br />db2 "disconnect current" > /dev/null 2>&1; #断开数据库<br /><!--c2--></div><!--ec2--><br /><br /><span style='color:red'>3. 查看分析结果</span><br />more report<br /><br /><span style='color:red'>4. over啦~ <!--emo&:)--><img src='style_emoticons/default/smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /><!--endemo--></span><br /><br />现在知道每个月,和谁发的短信最多! 谁是潜在的目标了 <!--emo&:P--><img src='style_emoticons/default/tongue.gif' border='0' style='vertical-align:middle' alt='tongue.gif' /><!--endemo--> <!--emo&:haha:--><img src='style_emoticons/default/haha.gif' border='0' style='vertical-align:middle' alt='haha.gif' /><!--endemo--> <!--emo&^_^--><img src='style_emoticons/default/happy.gif' border='0' style='vertical-align:middle' alt='happy.gif' /><!--endemo--><br /><br />附:报表样色<br /><!--QuoteBegin--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--QuoteEBegin--><br />PHONE NAME COUNT <br />----------- ------------------ -----------<br />137953**** aa 60<br />139147**** bb 120<br />139218**** cc 320<br /><!--QuoteEnd--></div><!--QuoteEEnd-->
2004-10-26 16:37
wildhorse
不错,呵呵,向你学习。
2004-10-29 20:40
无双
好啊 可以多用用<br /><br /><!--emo&:D--><img src='style_emoticons/default/laugh.gif' border='0' style='vertical-align:middle' alt='laugh.gif' /><!--endemo-->
2004-11-1 18:08
seven
<span style='color:red'>更新:</span><br />1. 修改sms2id表结构,添加type字段,做分类统计使用<br />2. 修改分析SQL语句<br />SQL解释:<br />2.1 value()函数是用来测试空值的,如为空用''代替<br />2.2 使用group by 的grouping sets子句<br />2.3 统计使用了聚集和钻取,由group by grouping sets((a.sms_details, b.type, b.phone, b.name),(b.type), ())语句来实现<br />3. 最后用order by b.type, a.sms_details, b.name来增强报表的可读性<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><br />db2 "select value(a.sms_details,'') as 电话号码, value(case when a.sms_details=b.phone then b.name else concat ('unknow_', a.sms_details) end,'') as 姓名, value(b.type,'') as 类别 , count(a.phoneno) as 统计 from sms_details a left outer join sms2id b on a.sms_details=b.phone group by grouping sets((a.sms_details, b.type, b.phone, b.name),(b.type), ()) order by b.type, a.sms_details, b.name"<br /><!--c2--></div><!--ec2--><br /><br />附报表样色:<br /><!--QuoteBegin--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--QuoteEBegin-->电话号码&nbsp; &nbsp;&nbsp; &nbsp; 姓名&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 类别&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; 统计<br />-----------&nbsp; ------------------&nbsp; &nbsp; &nbsp; ---------- -----------<br />139518***** TT&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 好友&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; 4<br />222333***** AA&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 好友&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; 2<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style='color:red'>好友&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 6</span><br />139147***** unknow_139147*****&nbsp; &nbsp; 其他&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; 1<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style='color:red'>其他&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1</span><br />111223***** BB&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 亲戚&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; 2<br />139211***** JJ&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 亲戚&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; 3<br />222333***** CC&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 亲戚&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; 1<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style='color:red'>亲戚&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 6</span><br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style='color:blue'>13</span><br /><!--QuoteEnd--></div><!--QuoteEEnd--><br />红色为小类统计<br />蓝色为总统计
2004-11-2 09:35
燕狂徒
支持原创,加精华
2004-11-15 17:07
jnnxjj
嘿嘿,我不用统计也知道自己每月给谁发的短信最多
2004-11-15 17:23
seven
呵呵,其实,这个贴我是抛出一个话题,<br /><br />DW,BI的东东,用到一些olap的函数<br /><br />其实也就是olap报表的应用开发,而不是真的为了分析我的短线话单 <!--emo&:blush:--><img src='style_emoticons/default/blush.gif' border='0' style='vertical-align:middle' alt='blush.gif' /><!--endemo--> <br /><br /><br />这个才是我真的的意图,可惜,响应的人不多<br />
页:
[1]
Powered by Discuz! Archiver 5.5.0
© 2001-2006 Comsenz Inc.