I have this
ID | Name
----+-------
31 | Abby
24 | Bruce
44 | Carl
49 | Derek
55 | Eric
81 | Fred
I want to concatenate groups of N rows into a single row. For N = 3, this would give me this
ID | Name
----------+----------------
31,24,44 | Abby,Bruce,Carl
49,55,81 | Derek,Eric,Fred
I managed to generate a row to use GROUP BY and CONCAT on, but it only works in mysql...
SET @row_number = 0;
SELECT *, (@row_number:=@row_number + 1) AS r1, (@row_number - 1) DIV 3 AS r2 FROM table1
ID | Name | r1| r2
----+-------+---+---
31 | Abby | 1 | 0
24 | Bruce | 2 | 0
44 | Carl | 3 | 0
49 | Derek | 4 | 1
55 | Eric | 5 | 1
81 | Fred | 6 | 1
For clarification:
I want a vanilla-like SQL solution (So it will work in mysql, sybase, oracle and postgres)
I don't need any order, I just want to reconstitute the original table at some point
I don't have writing privileges on this base, only reading
I want to concatenate any columns type (by casting them to a string) and handle NULLs
It's ok if some groups are not exactly of size N (like the last one)