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
РЕДАКТИРАНЕ
В случай, че искате само 4 на група, добавете променлива с номер на ред:
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