1、创建一个示例表,供演示用,语句如下:
create table test_concat
(
id int(10) primary_key auto_increment,
spec varchar(255) not null,
attribute varchar(255) not null
)ENGINE=MyISAM DEFAULT CHARSET=utf8;
在mysql工具navicat for mysql(其他工具也可以)下执行完毕,效果如图:

2、在数据库中插入几条数据,供演示用,数据如图:

3、在mysql工具navicat for mysql(其他工具也可以)下输入如下语句:
select spec,group_concat(attribute) from test_concat group by spec;
执行后结果如图:

4、这时候再通过程序来获取数据就是很轻松的事了。根据所使用的语言,选择合适的方法去获取相应数据,并进行处理就可以了。