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 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 

SELECT @n := @n + 1 as n, Nb, medec, prest, Nompatient, ftt, Categorie FROM (SELECT @n := 0, m.nom as medec, s.id as Nb, ft.id as ftt, sv.libelle , m.nom , pr.libelle as prest, p.nom as Nompatient, ct.libelle as Categorie from services sv, medecins m, sejours s, sejourprestations sjp, prestations pr, patients p, categoriepatients ct, factures ft WHERE sv.id = s.service_id 
AND s.medecin_id = m.id 
AND s.patient_id = p.id 
AND s.categorie_patient_id = ct.id 
AND sjp.sejour_id = s.id 
AND sjp.prestation_id = pr.id 
AND s.facture_id=ft.id 
AND day(s.created_at) = day(CURRENT_DATE)) AS ishmael GROUP BY n ORDER BY medec
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: