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.

Assign group value based on lag value change

325647Feb 20 2010 — edited Feb 20 2010

I have some old data that has a structure determined by order. The groups are in ascending order, based that the amount column, and delineated by when the previous value is less than the current value. I just need to assign a unique group ID to each group. This is what I have:

Order	Amount	Group
1	56
2	63
3	41
4	52
5	59
6	74
7	39
8	42
9	44
10	51
11	62
12	77

and this is what I would like:

Order	Amount	Group
1	56	1
2	63	1
3	41	2
4	52	2
5	59	2
6	74	2
7	39	3
8	42	3
9	44	3
10	51	3
11	62	3
12	77	3

I can get the previous value with the lag function but am struggling with assigning the number. I am a sql more than pl/sql person. TIA.

Comments

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

Post Details

Locked on Mar 20 2010
Added on Feb 20 2010
6 comments
8,751 views