I have a table representing product groups. Groups are defined by row number and their Type. Hence here we have 2 groups, the group is defined by the Type A, the Type B being components.
Row number | Type |
---|---|
0 | A |
1 | B |
2 | B |
3 | A |
4 | B |
5 | B |
With just this data, I need to find back the row number of the last preceeding Type A occurence :
Row number | Type | Row father |
---|---|---|
0 | A | 0 |
1 | B | 0 |
2 | B | 0 |
3 | A | 3 |
4 | B | 3 |
5 | B | 3 |
I can't find a way to get this. It's a sort of lag()
or first_value()
based on condition. Here I have 2 groups of 2 components, but I can have more groups with different sizes. The only thing that defines the group are the row number : every row number under Type A (so with Type B) is a child of the above Type A, until next type A.
Thank you for your help