I need help with creating sql query, I will present my problem in the picture
The photo above shows my prepared CTE table, what I want to achieve is table posted belove
Explanation
1. Column Group - If the value of the Type field is equal to T then we should set the next value starting from 1 to the next repetition of the value of T in the Type column
2. Column MaxGroupValueToPoint - Returns the largest value in the group it is in but we check from where the cursor is to the beginning of the group (sort by field id_ex asc)
CTE tabel contain 7+ million records
My problem is that I dont know how to achieve that group column.