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!

Counting number of consecutive days and only use greater than X days

1007410May 7 2013 — edited May 8 2013
I am using database version 11.2.0.1.0

I have data that looks like this:

ID Date: Value
55 2-24-2013 120
55 2-25-2013 126
55 2-26-2013 120
55 2-27-2013 130
55 3-01-2013 110
55 3-02-2013 126
55 3-05-2013 130
72 2-28-2013 120
72 3-01-2013 126
72 3-02-2013 120
72 3-10-2013 130
72 3-11-2013 110
72 3-12-2013 126
72 3-13-2013 130



So I would like to detemine the data that has more then 2 consecutive days and then take the change in value to get data like this.

ID Date: Value Delta
55 2-24-2013 120 Null
55 2-25-2013 126 6
55 2-26-2013 120 -6
55 2-27-2013 130 10
72 2-28-2013 120 Null
72 3-01-2013 126 6
72 3-02-2013 120 -6
72 3-10-2013 130 Null
72 3-11-2013 110 -20
72 3-12-2013 126 16
72 3-13-2013 130 -4


Any suggestions???? I am using SQL Developer 3.0.04 for this.

Edited by: 1004407 on May 7, 2013 9:03 AM

Edited by: 1004407 on May 7, 2013 9:11 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 5 2013
Added on May 7 2013
18 comments
2,507 views