I have a table that looks something like this when ORDERED by R_Value Desc
Note that it is important to understand that the below table is SQL SELECT ordered by R_Value
Id Letter R_Value
1 A 1500
2 A 1400
4 B 800
9 B 700
10 B 600
11 A 400
12 A 200
I want my result set to look like this. The result set needs to be grouped 3 times. Each time, the letter changes from A to B or vice versa, a new group should be formed.
Letter Max_RValue
A 1500
B 800
A 400
I have already experimented with various things- lead/lag functions, partitioning, etc. and it seems impossible. A simple Group by(Letter) obviously won't work because
all 'A' will be put in one group which is not what I want.
My next step would be to try this in a procedural language, dump it in an intermediate table and then read the results. Before doing that, is this even possible in Ordinary SQL?