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.

increment row number when value of field changes in Oracle

user4295847Mar 14 2017 — edited Mar 14 2017

I need help in writing a query in Oracle for the following data. The data is sorted by Person and Day fields.

Person    Day  Flag
  
------ --- ----
  person1 day1  1
  person1 day2  2
  person1 day3  1
  person1 day4  2
  person1 day5  1
  person1 day6  2
  person1 day7  3
  person1 day8  1

I need to have a Group_Number column that gets incremented whenever the Flag value start from '1'. My result should look as below

Person     Day    Flag Group_Number
  
------ ---     ---- ------------
  person1 day1    1   
1
  person1 day2    2   
1
  person1 day3    1    2

  person1 day4    2   
2
  person1 day5    1    3

  person1 day6    2   
3
  person1 day7    3   
3
  person1 day8    1    4

This post has been answered by James Su on Mar 14 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 11 2017
Added on Mar 14 2017
26 comments
6,282 views