I have a set of records, for example
A B
1 5
1 6
1 9
2 1
2 8
where we have two groups (A=1 and A=2) and inside groups record are ordered by values in B.
And I need to add a column with enumeration inside each group
A B C
1 5 1
1 6 2
1 9 3
2 1 1
2 8 2
I tried to use nested query to fetch a number of records that have a value in B less than for current record given the same group id (A) but it is too slow. I use some enumeration of rows in other part of code (using select @rownum:=@rownum+1 num) but I enumerate all records there. So I am interested, is it possible to implement it iside query (if possible I'd like to avoid cursor loops etc). Thanks!