I am trying to group separate rows which might be broken by a different group. If they are broken I want them to group separately.
So I have:
Col1 | Col2
---------------------
| Y |01/JAN/2012
| Y |01/FEB/2012
| N |01/MAR/2012
| Y |01/APR/2012
| Y |01/MAY/2012
I want to get the result:
|col1|col2 |GRP
---------------------
| Y |01/JAN/2012|1
| Y |01/FEB/2012|1
| N |01/MAR/2012|2
| Y |01/APR/2012|3
| Y |01/MAY/2012|3
How can I achieve this?
My current attempt is this:
select
Col1,
Col2,
dense_rank() over (partition by Col1 order by Col2 asc) as grp
from
myTABLE
;
but that groups all the 'Y's together and gives me a sequential number like this:
|col1|col2 |GRP
---------------------
| Y |01/JAN/2012|1
| Y |01/FEB/2012|2
| N |01/MAR/2012|1
| Y |01/APR/2012|3
| Y |01/MAY/2012|4