Oracle问题,请教各位大侠!
现在有一张表:
create table TEST
(
  apiname   VARCHAR2(50),
  starttime TIMESTAMP(6),
  endtime   TIMESTAMP(6)
);
数据有5条:
insert into TEST (apiname, starttime, endtime)
values ('Api1', to_timestamp('14-07-2013 00:40:39.000000', 'dd-mm-yyyy hh24:mi:ss.ff'), to_timestamp('14-07-2013 00:47:09.000000', 'dd-mm-yyyy hh24:mi:ss.ff'));
insert into TEST (apiname, starttime, endtime)
values ('Api2', to_timestamp('14-07-2013 00:47:22.000000', 'dd-mm-yyyy hh24:mi:ss.ff'), to_timestamp('14-07-2013 00:47:41.000000', 'dd-mm-yyyy hh24:mi:ss.ff'));
insert into TEST (apiname, starttime, endtime)
values ('Api1', to_timestamp('14-07-2013 00:49:29.000000', 'dd-mm-yyyy hh24:mi:ss.ff'), to_timestamp('14-07-2013 00:49:56.000000', 'dd-mm-yyyy hh24:mi:ss.ff'));
insert into TEST (apiname, starttime, endtime)
values ('Api2', to_timestamp('14-07-2013 00:55:16.000000', 'dd-mm-yyyy hh24:mi:ss.ff'), to_timestamp('14-07-2013 00:56:01.000000', 'dd-mm-yyyy hh24:mi:ss.ff'));
insert into TEST (apiname, starttime, endtime)
values ('Api1', to_timestamp('14-07-2013 00:45:35.000000', 'dd-mm-yyyy hh24:mi:ss.ff'), to_timestamp('14-07-2013 00:45:50.000000', 'dd-mm-yyyy hh24:mi:ss.ff'));
commit;apiName startTime endTime
Api1 14-7月 -13 08.40.39.000000 上午 14-7月 -13 12.47.09.000000 上午
Api2 14-7月 -13 08.47.22.000000 上午 14-7月 -13 12.47.41.000000 上午
Api1 14-7月 -13 08.49.29.000000 上午 14-7月 -13 12.49.56.000000 上午
Api2 14-7月 -13 08.55.16.000000 上午 14-7月 -13 12.56.01.000000 上午
Api1 14-7月 -13 08.45.35.000000 上午 14-7月 -13 12.45.50.000000 上午我想执行结果如下,每隔10分钟统计一次:每个Api的执行记录数:
Time apiName count
201307140840 Api1 3
201307140840 Api2 1
201307140850 Api2 1

解决方案 »

  1.   

    请教各位大虾,上面的SQL该怎么写啊 多谢
      

  2.   

    --oracle9i以上
    with a as (select apiname,to_char(starttime,'yyyymmddhh24mi') starttime from test),
    b as (select apiname,substr(starttime,0,10) || substr(starttime,11,1) || '0' exectime from a)
    select apiname,exectime,count(exectime) execcnt from b
    group by apiname,exectime