Initially, I have two variables x (group variable) and y, now I'd like to create a third variable z which within each group of x starts from 1 and increase by 1 whenever y changes. Please see the following example. Could someone help how I can realize it in sql server 2008?
Thanks a lot!
x: a a a a a a a a b b b b b b b b
y: 0 0 0 1 0 0 2 3 0 1 0 0 2 3 0 0
Finally, I'd like to create z like this:
x: a a a a a a a a b b b b b b b b
y: 0 0 0 1 0 0 2 3 0 1 0 0 2 3 0 0
z: 1 1 1 2 3 3 4 5 1 2 3 3 4 5 6 6