How to group rows in mysql to be as chunks with a specific size
How to group rows in mysql to be as chunks with a specific size ?
I have a table called
Which has these fields
I want to make a query which group users into chucks with the size of 3 names per row.
1 name1 2 name2 3 name4 4 name5 5 name5 6 name6 7 name7
result should be
name1,name2,name3 name4,name5,name6 name7
GROUP_CONCAT of course to do that
SELECT GROUP_CONCAT(name), (IF(@i = 3 OR @i IS NULL, @i:=1, @i:[email protected]+1 ))as idx, (IF(@gr_idx IS NULL, @gr_idx:=1, IF(@i = 1, @gr_idx:[email protected]_idx+1,@gr_idx) )) as gr_idx FROM users GROUP BY gr_idx
- A Linux, Apache, MySQL, PHP (LAMP) stack is a combination of open source software that is typically installed together to enable a server to host dynamic […]
- MySQL is an the most popular open-source database management system, in most of hosting company its has been bundle by LAMP(Linux, Apache, MySQL, PHP/Python/Perl) stack. Another alternative […]
- MySQL is the world’s most popular open-source database. Despite its powerful features, MySQL is simple to set up and easy to use. Below are some instructions […]