1、表结构:
create table tableName( `ID` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID', `name` varchar(20) NOT NULL AUTO_INCREMENT COMMENT 'name', )
2、插入例子数据:
insert into tableName values(1, 'one'); insert into tableName values(2, 'two'); insert into tableName values(3, '333'); insert into tableName values(4, 'sisi);
3、用逗号连接列的sql
select GROUP_CONCAT(name) as names from tableName
4、结果:
one,two,333,sisi