iamlaosong文
客服需要抽取妥投邮件进行回访,为了保证抽取的覆盖率,要求每个机构抽取几条,然后进行回访,语句如下:
select d.city, d.ssxs, d.zj_code, d.zj_mc, c.dlv_date,c.mail_num, c.dlv_sts_code
from tb_evt_dlv c, sncn_zd_jg d
where c.dlv_date = to_date('2015-12-7', 'yyyy-mm-dd')
and c.dlv_sts_code = 'I'
and c.dlv_bureau_org_code = d.zj_code
and c.mail_num in (select t.mail_num
from tb_evt_dlv t
where t.dlv_date = to_date('2015-12-7', 'yyyy-mm-dd')
and t.dlv_sts_code = 'I'
and t.dlv_bureau_org_code = c.dlv_bureau_org_code
and rownum <= 2)
order by d.zj_code;
上述语句是随机抽取的,由于我们是对虚假信息进行抽查,为了提高准确度,就需要对信息进行筛选,比如抽取下段和妥投时间间隔过小的邮件,语句如下(时间间隔600秒):
select d.city, d.ssxs, d.zj_code, d.zj_mc, c.dlv_date,c.mail_num, c.dlv_sts_code
from tb_evt_dlv c, sncn_zd_jg d
where c.dlv_date = to_date('2015-12-7','yyyy-mm-dd')
and c.dlv_sts_code = 'I'
and c.dlv_bureau_org_code = d.zj_code
and c.mail_num in (select t.mail_num
from tb_evt_dlv t,tb_evt_pseg_mail_rela v
where t.dlv_date = to_date('2015-12-7','yyyy-mm-dd')
and t.mail_num=v.mail_num
and t.dlv_date=v.seal_date
and t.dlv_sts_code = 'I'
and t.dlv_bureau_org_code = c.dlv_bureau_org_code
and (t.dlv_time - v.seal_time)*3600*24 <= 600
and rownum <= 2 )
order by d.zj_code;
需要注意的是,oracle中日期时间和Excel类似,虽然显示出来是日期+时间,但其值可以认为由整数和小数两部分组成,整数部分是距某日期的天数(Excel定义1900 年 1 月 1 日的值是1,oracle似乎从公元元年 1 月 1 日开始,公元前是负数,没有0值。Oracle9i SQL Reference文档中有:from January 1, 4712 BC to December 31, 9999 AD. 即公元前4712年1月1日到公元9999年12月31日),小数则是时间值,是以当前时间距0时的秒数除以24*3600得到的数据。所以,两个时间之差乘以24*3600就是以秒为单位的时间。同理,乘以24就是以小时为单位的时间,乘以24*60就是以分钟为单位的时间。