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!

Group by using row's order

802709Apr 4 2011 — edited Apr 4 2011
hi all,

one of my friends asked me a question and i feel that it can be done but how ?

without using PLSQL, can it be done by sql ?

we have a table and its data like that:
X   Y
----------
A   S
B   S
C   S
D   T
E   T
F   S
G   S
H   R
I want to order this data be field X (which is already done in this example) and group this data by Y field but if in the order the value of Y field changes, this means that will be a new group.

I mean, for this example, A, B and C records is a group, D and E is an another group and E and F is an another group. as you see ABC records and EF records has same Y field value (which is S) but I want to assume that they are different groups because of the order.

if I give a number the groups it looks like this:
X   Y
----------
A   S      1
B   S      1
C   S      1
D   T      2
E   T      2
F   S      3
G   S      3
H   R      4
I have 4 different group in here. any idea ?

PS: we dont want to use plsql, just sql
This post has been answered by Solomon Yakobson on Apr 4 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 2 2011
Added on Apr 4 2011
6 comments
140 views