I want to select an increment counter group by medec field please how to do this and i would like the output will be as below
You can emulate ROW_NUMBER() function in this way:

select
    rn, medec
from
    (select 
       medec,
       @rn := case when @last_medec = medec then @rn +  1 else 1 end rn,
       @last_medec := medec
     from
       tbl, (select @rn := 1, @last_medec := '') x
     order by
       medec) y




rn | medec 
-: | :-----
 1 | medec1
 2 | medec1
 1 | medec2
 2 | medec2



db&lt;>fiddle here

Have a look at this MySql tutorial: