I have a table with two columns.
+------+------+
| data | num |
+------+------+
| a | |
| a | |
| a | |
| b | |
| b |
it is something like this, but you will need to create procedure
create procedure procname()
begin
DECLARE done,i,j int DEFAULT 0;
DECLARE n,m nvarchar(500) DEFAULT '';
DECLARE cur CURSOR FOR SELECT d.data,d.num FROM tablename AS d ORDER BY DATA;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur;
read_loop: LOOP
set m = n;
SET j = i;
fetch cur into n,i;
IF n = m
THEN
SET i = i+1;
// UPDATE here your TABLE but you will need one more colomn to be able to UPDATE ONLY one RAW that you need
ELSE
SET i = 0; //RESET indexer
END IF;
IF done = 1 THEN
LEAVE read_loop;
END IF;
END LOOP read_loop;
CLOSE cur;
end