A 表字段(id(唯一),card_id(有重复),v_time,v_ip,v_location,v_sequence)
  给一个参数v_ip
  编写实现以时间为基础查询每两个小时内或者一个小时内出现50次的数据,先判断在这个小时内有没有50条数据,如果没有,直接查询下个小时,如果有50条数据,把多余的数据删除,只保留50条数据,可以是任意的,但是时间必须是连续的。
补充:时间字段,每个小时都有数据。请大家帮帮忙 谢谢!!

解决方案 »

  1.   

    --把下面代码里的表从test_yixl换成你的A即可:
    create or replace procedure test_yixl_proc
    as
    in_hour number(10) := 0;
    vn_cnt number(4) := 0;
    cursor c_cnt_perhour is
    select to_number(to_char(v_time, 'yyyymmddHH')), count(1) 
    from test_yixl group by to_number(to_char(v_time, 'yyyymmddHH'));
    begin
    open c_cnt_perhour;
    loop
    fetch c_cnt_perhour into in_hour, vn_cnt;
    exit when c_cnt_perhour%notfound;
    if vn_cnt >= 50 then
     delete from test_yixl where to_number(to_char(v_time, 'yyyymmddHH')) = in_hour 
                     and rownum <= vn_cnt - 50;
     commit;
    end if;
    end loop;
    close c_cnt_perhour;
    end test_yixl_proc;