SELECT language,id,g
FROM (
SELECT language,id,
CASE WHEN [email protected]+1 THEN @n ELSE @n:[email protected]+1 END AS g,
@lastid := id As b
FROM
t, (SELECT @n:=0) r
ORDER BY
id
) s
MODIFIER
Au cas où vous voudriez seulement 4 par groupe, ajoutez une variable de numéro de ligne :
SELECT language,id,g,rn
FROM (
SELECT language,id,
CASE WHEN [email protected]+1 THEN @n ELSE @n:[email protected]+1 END AS g,
@rn := IF(@lastid+1 = id, @rn + 1, 1) AS rn,
@lastid := id As dt
FROM
t, (SELECT @n:=0) r
ORDER BY
id
) s
Where rn <=4