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
EDIT
Jika Anda ingin hanya 4 per grup, tambahkan variabel nomor baris:
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