I have the attached table, I would like to group by ID and if there are consecutively same codes, group by codes, then pick the minimum valueA and maximun valueB within the group. I couldn't make it work, because if I group by ID and then group by code, then it picks all the same codes within the ID (not just the consecutive ones). Any help would be appreciated.