Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

LAST_VALUE suggestion

petezAug 11 2010 — edited Nov 2 2010
Hi Guys,

How to modify LAST_VALUE call in query

select t.*, last_value( order_val) over(order by order_date) from testx t

to get 12 for dates 7/1/2010, 8/1/2010, 9/1/2010

ID ORDER_DATE ORDER_VAL LAST_VALUE(ORDER_VAL)OVER(ORDE
1 1/1/2010 3 3
2 2/1/2010 5 5
3 3/1/2010 7 7
4 4/1/2010 8 8
5 5/1/2010 9 9
6 6/1/2010 12 12
7 7/1/2010 12
8 8/1/2010 12
9 9/1/2010 12

(Ora 9.2):

create table testx ( id number, order_date date, order_val number );
insert into testx values ( 1, to_date('2010-01-01','yyyy-mm-dd'), 3 );
insert into testx values ( 2, to_date('2010-02-01','yyyy-mm-dd'), 5 );
insert into testx values ( 3, to_date('2010-03-01','yyyy-mm-dd'), 7 );
insert into testx values ( 4, to_date('2010-04-01','yyyy-mm-dd'), 8 );
insert into testx values ( 5, to_date('2010-05-01','yyyy-mm-dd'), 9 );
insert into testx values ( 6, to_date('2010-06-01','yyyy-mm-dd'), 12 );
insert into testx values ( 7, to_date('2010-07-01','yyyy-mm-dd'), null );
insert into testx values ( 8, to_date('2010-08-01','yyyy-mm-dd'), null );
insert into testx values ( 9, to_date('2010-09-01','yyyy-mm-dd'), null );

Thanks,
Regards,
Piotr

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 8 2010
Added on Aug 11 2010
9 comments
1,235 views