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