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!

How to get the last different occurrence in a SCD table

547817Mar 26 2012 — edited Mar 26 2012
hey,
i have a slowly changing dimension and i want to get the last different occurrence for each row.

Sample Data
the field LAST_VALUE is the one i'm looking for.
 
ID	START_DATE	END_DATE	VALUE	LAST_VALUE
1	01/01/2000	01/02/2000	X	null
1	01/02/2000	01/03/2000	X	null
1	01/03/2000	01/04/2000	Y	X
1	01/04/2000	01/05/2000	Y	X
1	01/05/2000	01/06/2000	X	Y
1	01/06/2000	01/07/2000	X	Y
1	01/07/2000	01/08/2000	Z	X
1	01/08/2000	01/09/2000	Q	Z
i want to try and do that without three sub selects.
i've tried analytic functions but lag brings me the last occurrence which is not necessarily different.

thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 23 2012
Added on Mar 26 2012
5 comments
275 views