日期:2014-05-16  浏览次数:20493 次

oracle 自增序列及分组查询取某一条(row_number()函数)
-- Create sequence 
create sequence SEQ_C_PICRECORD
minvalue 1
maxvalue 9999999999
start with 21
increment by 1
cache 20;

--Create trigger
create or replace trigger tri_c_picrecord
before insert on c_picrecord for each row
begin
  select seq_c_picrecord.nextval into:new.id from dual;
end;

?

select *
  from (select t.*,
               row_number() over(partition by car_num, car_numcolor order by cap_date) as rn from
? c_picrecord t) a
 where a.rn = 3