puede simular el particionado row_number usando variables de usuario y luego limitar filas y aplicar GROUP_CONCAT:
Considere la siguiente tabla:
create table your_table (
id int primary key autoincrement,
category int,
value int
);
y datos:
insert into your_table (category, value)
values
(1, 1), (1, 2), (1, 3), (1, 4), (1, 5),
(2, 6), (2, 7), (2, 8), (2, 9), (2, 10),
(3, 11), (3, 12), (3, 13), (3, 14), (3, 15);
y queremos es el valor superior 3 (en el orden de la última identificación) por categoría concatenada:
select category,
group_concat(value order by id desc) as value_con
from (
select t.*,
@rn := if(@category = category, @rn + 1, if(@category := category,1, 1)) as seqnum
from your_table t
cross join (select @category := null, @rn := 0) x
order by t.category, t.id desc
) t
where seqnum <= 3
group by category;
Salida:
category value_con
1 5,4,3
2 10,9,8
3 15,14,13
Aquí está una demo de este.
aumento en el valor group_concat_max_len my.cnf – Omesh
puede ser que usted puede obtener su respuesta aquí http://stackoverflow.com/questions/3378324/limit-ignored-in-query-with-group-concat http://stackoverflow.com/questions/23608464/group-concat-with-limit –