oracle 按15分钟间隔查询提

来源:百度知道 编辑:UC知道 时间:2024/06/01 02:16:26
请教大家一个问题:
我现在需要做这么样的一个操作,从数据库中取出一个时间字段time,同时取出一个计数的字段,然后把一天96等分,即每15分钟为一个时间段,把这15分钟内计数字段的值相加起来,请问怎么做?
如果记录是这样子的:
2009-4-11 10:05:00,2009-4-11 10:10:00,2009-4-11 10:15:00
这三条记录是在十点0分到十点十五分之间,那么sum(3条记录的计数字段值),以此类推。

简单说了,就是股票的K线15分钟那样子划分,但我需要将这15分钟内的数据加起来。

急啊,请大家帮帮忙。我想了半天了。

我试验了一下,应该可以,你可以试试。我试验的前提
create table test3(t1 date,t2 number);

insert into test3 values(to_date('20090103010100','yyyymmddhh24miss'),1);
...

create or replace view test3_v as
select rownum id,t1,t2 from
(select to_char(t1,'yyyymmddhh24miss') t1,t2 from test3;

set serveroutput on;
declare
test3_rec1 test3_v%rowtype;
test3_rec2 test3_v%rowtype;
max_temp number;
sum_temp number;
begin
select max(id) into max_temp from test3_v;
if max_temp<>0 then
select * into test3_rec1 from test3_v where id = 1;
sum_temp:=test3_rec1.t2;
for i in 2..max_temp
loop
select * into test3_rec2 from test3_v where id = i;
if (test3_rec2.t1-test3_rec1.t1)<=to_char(0000001460) then
sum_temp:=sum_temp+test3_rec2.t2;
else
dbms_output.put_line(concat('ans=',sum_temp));
test3_rec1.t2:=test3_rec2.t2
sum_temp:=test3_rec1.t