with test as (
select 'A' as col_a , '2012-11-23 14:38:20' as col_b from dual
union all
select 'B' as col_a , '2012-11-23 14:38:28' as col_b from dual
union all
select 'C' as col_a , '2012-11-23 14:38:30' as col_b from dual
union all
select 'D' as col_a , '2012-11-23 14:38:31' as col_b from dual
union all
select 'D' as col_a , '2012-11-23 14:38:29' as col_b from dual
)
SELECT col_a,col_b FROM (
SELECT col_a,col_b,TO_CHAR(TO_DATE(col_b,'YYYY-MM-DD HH24:MI:SS'),'YYYYMMDDHHMISS') AS col_bNUM ,
MIN(TO_CHAR(TO_DATE(col_b,'YYYY-MM-DD HH24:MI:SS'),'YYYYMMDDHHMISS')) keep (DENSE_RANK FIRST ORDER BY col_b DESC) over(partition by NULL) AS STR
FROM TEST ORDER BY COL_B DESC)
WHERE STR-col_bNUM <11
如果是按10S一个时间段来统计数据的话,可参照如下脚本:
select to_char(trunc(the_date)+trunc(to_char(the_date,'sssss')/10)/8640,'hh24:mi:ss') period,
count(1) the_num
from table
where the_date>=date'2012-11-1'
and the_date<date'2012-11-2'
group by to_char(trunc(the_date)+trunc(to_char(the_date,'sssss')/10)/8640,'hh24:mi:ss');
日期可以自己修改。
其中,to_char(the_date,'sssss')是指将具体的日期的时分秒部分都换算成秒数,/10是指看这个秒数折合成多少个10秒,/8640是指看具体某一个10秒是在当天的第几个10秒上(8640是指一天有8640个10秒)。