我的一个统计时间片是截取到分钟的 现在我想把他弄成5秒内 请高手帮帮select mobile, trunc(savetime, 'mi'), count(mid)  from test.waphistory
  where savetime>=to_date('2008-10-1','yyyy-mm-dd') and savetime<to_date('2008-11-1','yyyy-mm-dd') and actionid in(1,4) and mobile<>0
  group by mobile, trunc(savetime, 'mi')
  having count(mid) >1

解决方案 »

  1.   

    SQL> select to_char(trunc(sysdate, 'mi')+trunc(to_number(to_char(sysdate,'ss'))/
    5)*5/(24*60*60), 'yyyy-mm-dd hh24:mi:ss') fivesec, to_char(sysdate, 'yyyy-mm-dd
    hh24:mi:ss') realtime from dual;FIVESEC             REALTIME
    ------------------- -------------------
    2009-07-14 22:26:05 2009-07-14 22:26:09SQL> select to_char(trunc(sysdate, 'mi')+trunc(to_number(to_char(sysdate,'ss'))/
    5)*5/(24*60*60), 'yyyy-mm-dd hh24:mi:ss') fivesec, to_char(sysdate, 'yyyy-mm-dd
    hh24:mi:ss') realtime from dual;FIVESEC             REALTIME
    ------------------- -------------------
    2009-07-14 22:26:10 2009-07-14 22:26:11
      

  2.   

    SQL> select to_char(trunc(sysdate, 'mi')+trunc(to_number(to_char(sysdate,'ss'))/
    5)*5/(24*60*60), 'yyyy-mm-dd hh24:mi:ss') fivesec, to_char(sysdate, 'yyyy-mm-dd
    hh24:mi:ss') realtime from dual;FIVESEC                   REALTIME
    -------------------       -------------------
    2009-07-14 22:26:55       2009-07-14 22:26:57SQL> select to_char(trunc(sysdate, 'mi')+trunc(to_number(to_char(sysdate,'ss'))/
    5)*5/(24*60*60), 'yyyy-mm-dd hh24:mi:ss') fivesec, to_char(sysdate, 'yyyy-mm-dd
    hh24:mi:ss') realtime from dual;FIVESEC                   REALTIME
    -------------------       -------------------
    2009-07-14 22:27:00       2009-07-14 22:27:03
    可以把你的改为
    select mobile, trunc(savetime, 'mi'), count(mid)  from test.waphistory 
      where savetime>=to_date('2008-10-1','yyyy-mm-dd') and savetime <to_date('2008-11-1','yyyy-mm-dd') and actionid in(1,4) and mobile <>0 
      group by mobile, to_date(trunc(savetime, 'mi')+trunc(to_number(to_char(savetime,'ss'))/5)*5/(24*60*60))
      having count(mid) >1
      

  3.   

    select mobile,to_date(trunc(savetime, 'mi')+trunc(to_number(to_char(savetime,'ss'))/5)*5/(24*60*60)) , count(mid)  from test.waphistory 
      where savetime>=to_date('2008-10-1','yyyy-mm-dd') and savetime <to_date('2008-11-1','yyyy-mm-dd') and actionid in(1,4) and mobile <>0 
      group by mobile, to_date(trunc(savetime, 'mi')+trunc(to_number(to_char(savetime,'ss'))/5)*5/(24*60*60)) 
      having count(mid) >1 楼上 应该是这样,但我看了结果 与实际不符合 唉~·~ 谢谢!!
      

  4.   


    不好意思,应该是把to_date拿走也就是
    select mobile, trunc(savetime, 'mi'), count(mid)  from test.waphistory 
      where savetime>=to_date('2008-10-1','yyyy-mm-dd') and savetime <to_date('2008-11-1','yyyy-mm-dd') and actionid in(1,4) and mobile <>0 
      group by mobile, trunc(savetime, 'mi')+trunc(to_number(to_char(savetime,'ss'))/5)*5/(24*60*60) 
      having count(mid) >1 
      

  5.   

    select mobile, trunc(savetime, 'mi'), count(mid)  from test.waphistory 
      where savetime>=to_date('2008-10-1','yyyy-mm-dd') and savetime <to_date('2008-11-1','yyyy-mm-dd') and actionid in(1,4) and mobile <>0 
      group by mobile, trunc(savetime, 'mi')+trunc(to_number(to_char(savetime,'ss'))/5)*5/(24*60*60) 
      having count(mid) >1 这个语句报了ora-00970 不是group by 表达式 的错误 还是不行 谢谢!!!
      

  6.   

    由以前的1分钟改为5秒钟的片段,统计因子变小,肯定出来的统计量会多于一分钟的,你只所以觉得不对,是因为你前面select里的没有修改过来
    把select里的trunc也改过来就可以了。
      

  7.   

    你看看我写的sample的例子,理解一下写的方法,没有你的数据库,所以,我只是用sample测试了一下时间分段是正确的就没有数据做group by了。
      

  8.   

    嗯 非常感谢楼上的 我没有说清楚吧
    select mobile, trunc(savetime, 'mi'), count(mid)  from test.waphistory 
      where savetime>=to_date('2008-10-1','yyyy-mm-dd') and savetime <to_date('2008-11-1','yyyy-mm-dd') and actionid in(1,4) and mobile <>0 
      group by mobile, trunc(savetime, 'mi') 
      having count(mid) >1 我这个语句是统计一分钟内一个号码的产生多条mid 我把他统计成一条 截取了1分钟的时间片 现在我想把时间片变成5秒钟内的也就我要的结果是统计5秒内钟有mid》1的记录有多少 谢谢 非常谢谢!!
      

  9.   

    select mobile, trunc(savetime, 'mi')+trunc(to_number(to_char(savetime,'ss'))/5)*5/(24*60*60) timeslide, count(1)  from test.waphistory 
      where savetime>=to_date('2008-10-1','yyyy-mm-dd') and savetime <to_date('2008-11-1','yyyy-mm-dd') and actionid in(1,4) and mobile <>0 
      group by mobile, trunc(savetime, 'mi')+trunc(to_number(to_char(savetime,'ss'))/5)*5/(24*60*60) 
      having count(1) >1你需要把select里的也改的和后面一样的,试试上面这个。如果这个不是你想要的结果的话,就是我理解错了。
      

  10.   

    select mobile, trunc(savetime, 'mi')+trunc(to_number(to_char(savetime,'ss'))/5)*5/(24*60*60) timeslide, count(1)  from      (select distinct savetime ,mobile from  test.waphistory )  as  T_waphistory 
      where savetime>=to_date('2008-10-1','yyyy-mm-dd') and savetime <to_date('2008-11-1','yyyy-mm-dd') and actionid in(1,4) and mobile <>0 
      group by mobile, trunc(savetime, 'mi')+trunc(to_number(to_char(savetime,'ss'))/5)*5/(24*60*60) 
      having count(1) >1 
      

  11.   

    select mobile, trunc(savetime, 'mi')+trunc(to_number(to_char(savetime,'ss'))/5)*5/(24*60*60) timeslide, count(1)  from      (select distinct savetime ,mobile,actionid from  test.waphistory )  
      where savetime>=to_date('2008-10-1','yyyy-mm-dd') and savetime <to_date('2008-11-1','yyyy-mm-dd') and actionid in(1,4) and mobile <>0 
      group by mobile, trunc(savetime, 'mi')+trunc(to_number(to_char(savetime,'ss'))/5)*5/(24*60*60) 
      having count(1) >1 ;楼上的有点小错误 我改了过来了 谢谢 我已经结了贴 不能在再给分 所以只好在这里说声谢谢了!