i need assign incrementing value each string concatenated row starting @ 0 each row in result.
here's simplified data sample:
number|color 1 |red 1 |blue 1 |orange 2 |brown 3 |purple 3 |yellow this result need:
number|color_set 1 |0 red,1 blue,2 orange 2 |0 brown 3 |0 purple,1 yellow this result get:
number|color_set 1 |0 red,1 blue,2 orange 2 |3 brown 3 |4 purple,5 yellow this i've been trying:
set @x:=0; select number, group_concat(@x:=@x+1,' ',color separator ',') table group number; the variable needs reset 0 each result row. i'm no expert , i'm new site appreciated.
thanks,
jay
just fun...
create table colors(color_set int not null,color varchar(12) not null,primary key (color_set,color)); insert colors values (1 ,'red'), (1 ,'blue'), (1 ,'orange'), (2 ,'brown'), (3 ,'purple'), (3 ,'yellow'); select color_set , group_concat(concat_ws(' ',n,color) order n) array ( select c.* , find_in_set(color,x)-1 n colors c join ( select color_set , group_concat(color order length(color),color) x colors group color_set ) y on y.color_set = c.color_set ) z group color_set; +-----------+-----------------------+ | color_set | array | +-----------+-----------------------+ | 1 | 0 red,1 blue,2 orange | | 2 | 0 brown | | 3 | 0 purple,1 yellow | +-----------+-----------------------+
Comments
Post a Comment